diff --git a/404.html b/404.html index 91728b3..7ea6beb 100644 --- a/404.html +++ b/404.html @@ -1,66 +1,27 @@ - - -
- + + + + -Developed by Paul Campbell.
+Developed by Paul Campbell.
Copyright (c) 2021 shinyauthr authors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@@ -124,31 +62,27 @@Developed by Paul Campbell.
+Developed by Paul Campbell.
Paul Campbell. Author, maintainer. +
+Michael Dewar. Contributor. +
+DESCRIPTION
+ Paul Campbell. Author, maintainer. -
-Michael Dewar. Contributor. -
-Campbell P (2022). +shinyauthr: 'Shiny' Authentication Modules. +R package version 1.0.0.9000, https://github.com/paulc91/shinyauthr. +
+@Manual{, + title = {shinyauthr: 'Shiny' Authentication Modules}, + author = {Paul Campbell}, + year = {2022}, + note = {R package version 1.0.0.9000}, + url = {https://github.com/paulc91/shinyauthr}, +}
Developed by Paul Campbell.
+Developed by Paul Campbell.
shinyauthr
is an R package providing module functions that can be used to add an authentication layer to your shiny apps.
You can install the package from CRAN.
+shinyauthr
is an R package providing module functions that can be used to add an authentication layer to your shiny apps.
You can install the package from CRAN.
-install.packages("shinyauthr")
Or the development version from github with the remotes package.
+install.packages("shinyauthr")
Or the development version from github with the remotes package.
-remotes::install_github("paulc91/shinyauthr")
remotes::install_github("paulc91/shinyauthr")
Code for example apps using various UI frameworks can be found in inst/shiny-examples. You can launch 3 example apps with the runExample
function.
# login with user1 pass1 or user2 pass2
@@ -98,9 +98,9 @@
shinyauthr::runExample("shinydashboard")
shinyauthr::runExample("navbarPage")
The package provides 2 module functions each with a UI and server element:
loginUI()
logoutUI()
logoutServer()
Note: the server modules use shiny’s new (version >= 1.5.0) shiny::moduleServer
method as opposed to the shiny::callModule
method used by the now deprecated shinyauthr::login
and shinyauthr::logout
functions. These functions will remain in the package for backwards compatibility but it is recommended you migrate to the new server functions. This will require some adjustments to the module server function calling method used in your app. For details on how to migrate see the ‘Migrating from callModule to moduleServer’ section of Modularizing Shiny app code.
Below is a minimal reproducible example of how to use the authentication modules in a shiny app. Note that this package invisibly calls shinyjs::useShinyjs()
internally and there is no need for you to do so yourself (although there is no harm if you do).
Note: the server modules use shiny’s new (version >= 1.5.0) shiny::moduleServer
method as opposed to the shiny::callModule
method used by the now deprecated shinyauthr::login
and shinyauthr::logout
functions. These functions will remain in the package for backwards compatibility but it is recommended you migrate to the new server functions. This will require some adjustments to the module server function calling method used in your app. For details on how to migrate see the ‘Migrating from callModule to moduleServer’ section of Modularizing Shiny app code.
Below is a minimal reproducible example of how to use the authentication modules in a shiny app. Note that this package invisibly calls shinyjs::useShinyjs()
internally and there is no need for you to do so yourself (although there is no harm if you do).
-library(shiny)
+library(shiny)
# dataframe that holds usernames, passwords and other user data
-user_base <- tibble::tibble(
- user = c("user1", "user2"),
- password = c("pass1", "pass2"),
- permissions = c("admin", "standard"),
- name = c("User One", "User Two")
+user_base <- tibble::tibble(
+ user = c("user1", "user2"),
+ password = c("pass1", "pass2"),
+ permissions = c("admin", "standard"),
+ name = c("User One", "User Two")
)
-ui <- fluidPage(
+ui <- fluidPage(
# add logout button UI
- div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
+ div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
# add login panel UI function
shinyauthr::loginUI(id = "login"),
# setup table output to show user info after login
- tableOutput("user_table")
+ tableOutput("user_table")
)
server <- function(input, output, session) {
@@ -139,27 +139,27 @@
data = user_base,
user_col = user,
pwd_col = password,
- log_out = reactive(logout_init())
+ log_out = reactive(logout_init())
)
# call the logout module with reactive trigger to hide/show
logout_init <- shinyauthr::logoutServer(
id = "logout",
- active = reactive(credentials()$user_auth)
+ active = reactive(credentials()$user_auth)
)
- output$user_table <- renderTable({
+ output$user_table <- renderTable({
# use req to only render results when credentials()$user_auth is TRUE
- req(credentials()$user_auth)
+ req(credentials()$user_auth)
credentials()$info
})
}
-shinyApp(ui = ui, server = server)
When the login module is called, it returns a reactive list containing 2 elements:
user_auth
The initial values of these variables are FALSE
and NULL
respectively. However, given a data frame or tibble containing user names, passwords and other user data (optional), the login module will assign a user_auth
value of TRUE
if the user supplies a matching user name and password. The value of info
then becomes the row of data associated with that user which can be used in the main app to control content based on user permission variables etc.
The logout button will only show when user_auth
is TRUE
. Clicking the button will reset user_auth
back to FALSE
which will hide the button and show the login panel again.
You can set the code in your server functions to only run after a successful login through use of the req()
function inside all reactives, renders and observers. In the example above, using req(credentials()$user_auth)
inside the renderTable
function ensures the table showing the returned user information is only rendered when user_auth
is TRUE
.
You can set the code in your server functions to only run after a successful login through use of the req()
function inside all reactives, renders and observers. In the example above, using req(credentials()$user_auth)
inside the renderTable
function ensures the table showing the returned user information is only rendered when user_auth
is TRUE
.
Most authentication systems use browser cookies to avoid returning users having to re-enter their user name and password every time they return to the app. shinyauthr
provides a method for cookie-based automatic login, but you must create your own functions to save and load session info into a database with persistent data storage.
Most authentication systems use browser cookies to avoid returning users having to re-enter their user name and password every time they return to the app. shinyauthr
provides a method for cookie-based automatic login, but you must create your own functions to save and load session info into a database with persistent data storage.
The first required function must accept two parameters user
and session
. The first of these is the user name for log in. The second is a randomly generated string that identifies the session. The app asks the user’s web browser to save this session id as a cookie.
The second required function is called without parameters and must return a data.frame of valid user
and session
ids. If the user’s web browser sends your app a cookie which appears in the session
column, then the corresponding user
is automatically logged in.
Pass these functions to the login module via shinyauthr::loginServer(...)
as the cookie_setter
and cookie_getter
parameters. A minimal example, using RSQLite as a local database to write and store user session data, is below.
Pass these functions to the login module via shinyauthr::loginServer(...)
as the cookie_setter
and cookie_getter
parameters. A minimal example, using RSQLite as a local database to write and store user session data, is below.
-library(shiny)
-library(dplyr)
-library(lubridate)
-library(DBI)
-library(RSQLite)
+library(shiny)
+library(dplyr)
+library(lubridate)
+library(DBI)
+library(RSQLite)
# connect to, or setup and connect to local SQLite db
-if (file.exists("my_db_file")) {
- db <- dbConnect(SQLite(), "my_db_file")
+if (file.exists("my_db_file")) {
+ db <- dbConnect(SQLite(), "my_db_file")
} else {
- db <- dbConnect(SQLite(), "my_db_file")
- dbCreateTable(db, "sessionids", c(user = "TEXT", sessionid = "TEXT", login_time = "TEXT"))
+ db <- dbConnect(SQLite(), "my_db_file")
+ dbCreateTable(db, "sessionids", c(user = "TEXT", sessionid = "TEXT", login_time = "TEXT"))
}
# a user who has not visited the app for this many days
@@ -199,35 +199,35 @@
# successfully logs in with a password. This function saves to your database.
add_sessionid_to_db <- function(user, sessionid, conn = db) {
- tibble(user = user, sessionid = sessionid, login_time = as.character(now())) %>%
- dbWriteTable(conn, "sessionids", ., append = TRUE)
+ tibble(user = user, sessionid = sessionid, login_time = as.character(now())) %>%
+ dbWriteTable(conn, "sessionids", ., append = TRUE)
}
# This function must return a data.frame with columns user and sessionid Other columns are also okay
# and will be made available to the app after log in as columns in credentials()$user_auth
get_sessionids_from_db <- function(conn = db, expiry = cookie_expiry) {
- dbReadTable(conn, "sessionids") %>%
- mutate(login_time = ymd_hms(login_time)) %>%
- as_tibble() %>%
- filter(login_time > now() - days(expiry))
+ dbReadTable(conn, "sessionids") %>%
+ mutate(login_time = ymd_hms(login_time)) %>%
+ as_tibble() %>%
+ filter(login_time > now() - days(expiry))
}
# dataframe that holds usernames, passwords and other user data
-user_base <- tibble::tibble(
- user = c("user1", "user2"),
- password = c("pass1", "pass2"),
- permissions = c("admin", "standard"),
- name = c("User One", "User Two")
+user_base <- tibble::tibble(
+ user = c("user1", "user2"),
+ password = c("pass1", "pass2"),
+ permissions = c("admin", "standard"),
+ name = c("User One", "User Two")
)
-ui <- fluidPage(
+ui <- fluidPage(
# add logout button UI
- div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
+ div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
# add login panel UI function
shinyauthr::loginUI(id = "login", cookie_expiry = cookie_expiry),
# setup table output to show user info after login
- tableOutput("user_table")
+ tableOutput("user_table")
)
server <- function(input, output, session) {
@@ -235,7 +235,7 @@
# call the logout module with reactive trigger to hide/show
logout_init <- shinyauthr::logoutServer(
id = "logout",
- active = reactive(credentials()$user_auth)
+ active = reactive(credentials()$user_auth)
)
# call login module supplying data frame, user and password cols
@@ -249,46 +249,46 @@
sessionid_col = sessionid,
cookie_getter = get_sessionids_from_db,
cookie_setter = add_sessionid_to_db,
- log_out = reactive(logout_init())
+ log_out = reactive(logout_init())
)
# pulls out the user information returned from login module
- user_data <- reactive({
+ user_data <- reactive({
credentials()$info
})
- output$user_table <- renderTable({
+ output$user_table <- renderTable({
# use req to only render results when credentials()$user_auth is TRUE
- req(credentials()$user_auth)
- user_data() %>%
- mutate(across(starts_with("login_time"), as.character))
+ req(credentials()$user_auth)
+ user_data() %>%
+ mutate(across(starts_with("login_time"), as.character))
})
}
-shinyApp(ui = ui, server = server)
sodium
+sodium
+
If you are hosting your user passwords on the internet, it is a good idea to first encrypt them with a hashing algorithm. You can use the sodium package to do this. Sodium uses a slow hashing algorithm that is specifically designed to protect stored passwords from brute-force attacks. More on this here. You then tell the shinyauthr::loginServer
module that your passwords have been hashed by sodium
and shinyauthr
will then decrypt when login is requested. Your plain text passwords must be a character vector, not factors, when hashing for this to work as shiny inputs are passed as character strings.
If you are hosting your user passwords on the internet, it is a good idea to first encrypt them with a hashing algorithm. You can use the sodium package to do this. Sodium uses a slow hashing algorithm that is specifically designed to protect stored passwords from brute-force attacks. More on this here. You then tell the shinyauthr::loginServer
module that your passwords have been hashed by sodium
and shinyauthr
will then decrypt when login is requested. Your plain text passwords must be a character vector, not factors, when hashing for this to work as shiny inputs are passed as character strings.
For example, a sample user base like the following can be incorporated for use with shinyauthr
:
# create a user base then hash passwords with sodium
# then save to an rds file in app directory
-library(sodium)
+library(sodium)
-user_base <- tibble::tibble(
- user = c("user1", "user2"),
- password = purrr::map_chr(c("pass1", "pass2"), sodium::password_store),
- permissions = c("admin", "standard"),
- name = c("User One", "User Two")
+user_base <- tibble::tibble(
+ user = c("user1", "user2"),
+ password = purrr::map_chr(c("pass1", "pass2"), sodium::password_store),
+ permissions = c("admin", "standard"),
+ name = c("User One", "User Two")
)
-saveRDS(user_base, "user_base.rds")
# in your app code, read in the user base rds file
-user_base <- readRDS("user_base.rds")
# then when calling the module set sodium_hashed = TRUE
credentials <- shinyauthr::loginServer(
@@ -297,21 +297,21 @@
user_col = user,
pwd_col = password,
sodium_hashed = TRUE,
- log_out = reactive(logout_init())
+ log_out = reactive(logout_init())
)
shinyauthr
originally borrowed some code from treysp’s shiny_password template with the goal of making implementation simpler for end users and allowing the login/logout UIs to fit easily into any UI framework, including shinydashboard.
Thanks to Michael Dewar for his contribution of cookie-based authentication. Some code was borrowed from calligross’s Shiny Cookie Based Authentication Example and from an earlier PR from aqualogy.
+shinyauthr
originally borrowed some code from treysp’s shiny_password template with the goal of making implementation simpler for end users and allowing the login/logout UIs to fit easily into any UI framework, including shinydashboard.
Thanks to Michael Dewar for his contribution of cookie-based authentication. Some code was borrowed from calligross’s Shiny Cookie Based Authentication Example and from an earlier PR from aqualogy.
I’m not a security professional so cannot guarantee this authentication procedure to be foolproof. It is ultimately the shiny app developer’s responsibility not to expose any sensitive content to the client without the necessary login criteria being met.
I would welcome any feedback on any potential vulnerabilities in the process. I know that apps hosted on a server without an SSL certificate could be open to interception of user names and passwords submitted by a user. As such I would not recommend the use of shinyauthr without a HTTPS connection.
-For apps intended for use within commercial organisations, I would recommend one of RStudio’s commercial shiny hosting options, or shinyproxy, both of which have built in authentication options.
+For apps intended for use within commercial organisations, I would recommend one of RStudio’s commercial shiny hosting options, or shinyproxy, both of which have built in authentication options.
However, I hope that having an easy-to-implement open-source shiny authentication option like this will prove useful when alternative options are not feasible.
Paul Campbell
Developed by Paul Campbell.
+ +Developed by Paul Campbell.
loginServer
and logoutServer
functions added. login
and logout
are now deprecated, full details in README.loginServer
and logoutServer
functions added. login
and logout
are now deprecated, full details in README.If you plan to use hashed passwords with shinyauthr you now must use the sodium package to hash your passwords and the sodium_hashed = TRUE
argument of the shinyauthr::login
module call for decryption to work appropriately.
If you plan to use hashed passwords with shinyauthr you now must use the sodium package to hash your passwords and the sodium_hashed = TRUE
argument of the shinyauthr::login
module call for decryption to work appropriately.
This means that previously used hashed
and algo
arguments that interfaced with the digest
package are now deprecated. If you had previously hashed your passwords with the digest package to use with shinyauthr, please re-hash them with sodium
and use the sodium_hashed
argument instead.
Sorry for this breaking change, but sodium hashing provides added protection against brute-force attacks on stored passwords. More information on this here.
+Sorry for this breaking change, but sodium hashing provides added protection against brute-force attacks on stored passwords. More information on this here.
Developed by Paul Campbell.
+Developed by Paul Campbell.
These functions silently reject all cookies during login and ignore requests to save session -ids to a database. Use these if you don't want to allow automatic login with cookies. These are -default values for `callModule(shinyauthr::login, ...)`. Replace them with your own functions which -get and set the user and session ids in a database.
-default_cookie_getter(user_string, session_string) - -default_cookie_setter(user, session)- -
user | -character string representing the user id |
-
---|---|
session | -character string representing the session id |
-
`default_cookie_setter` returns a data.frame with zero rows and two columns: `user` and `session`
- -Developed by Paul Campbell.
-Site built with pkgdown 1.6.1.
-Developed by Paul Campbell.
+Developed by Paul Campbell.
This is used to generate the Javascript which gets and sets the cookies in the -user's browser. We need to glue it together to handle the variable expiry time and -to get the correct module namespace. This function is used internally only.
-js_cookie_to_r_code(id, expire_days = 7)- -
id | -name of input object to hold the cookie value |
-
---|---|
expire_days | -number of days to ask browser to retain cookie |
-
Character string of Javascript code
- --if (FALSE) { -shinyjs::extendShinyjs( - text = js_cookie_to_r_code(ns("jscookie")), - functions = c("getcookie", "setcookie", "rmcookie") -) -} -
Developed by Paul Campbell.
-Site built with pkgdown 1.6.1.
-R/internal.R
- js_return_click.Rd
Javascript code to trigger login button with return key
-js_return_click(idpassword, idbutton)- -
idpassword | -name of password input, with correct namespace |
-
---|---|
idbutton | -name of action button, with correct namespace |
-
Developed by Paul Campbell.
-Site built with pkgdown 1.6.1.
-This code is minified from the GitHub project js-cookie/js-cookie. We include it here -to make the shinyauthr package more self-contained
-jscookie_script()- - - -
Developed by Paul Campbell.
-Site built with pkgdown 1.6.1.
-Deprecated. Use loginServer instead.
+Deprecated. Use loginServer instead.
input | -shiny input |
-
---|---|
output | -shiny output |
-
session | -shiny session |
-
data | -data frame or tibble containing usernames, passwords and other user data |
-
user_col | -bare (unquoted) column name containing usernames |
-
pwd_col | -bare (unquoted) column name containing passwords |
-
sodium_hashed | -have the passwords been hash encrypted using the sodium package? defaults to FALSE |
-
hashed | -Deprecated. shinyauthr now uses the sodium package for password hashing and decryption. If you have previously hashed your passwords with the digest package to use with shinyauthr please re-hash them with sodium for decryption to work. |
-
algo | -Deprecated |
-
log_out | -[reactive] supply the returned reactive from logout here to trigger a user logout |
-
sessionid_col | -bare (unquoted) column name containing session ids |
-
cookie_getter | -a function that returns a data.frame with at least two columns: user and session |
-
cookie_setter | -a function with two parameters: user and session. The function must save these to a database. |
-
reload_on_logout | -should app force reload on logout? |
-
shiny input
shiny output
shiny session
data frame or tibble containing usernames, passwords and other user data
bare (unquoted) column name containing usernames
bare (unquoted) column name containing passwords
have the passwords been hash encrypted using the sodium package? defaults to FALSE
Deprecated. shinyauthr now uses the sodium package for password hashing and decryption. If you have previously hashed your passwords with the digest package to use with shinyauthr please re-hash them with sodium for decryption to work.
Deprecated
[reactive] supply the returned reactive from logout here to trigger a user logout
bare (unquoted) column name containing session ids
a function that returns a data.frame with at least two columns: user and session
a function with two parameters: user and session. The function must save these to a database.
should app force reload on logout?
The module will return a reactive 2 element list to your main application.
First element user_auth
is a boolean indicating whether there has been
a successful login or not. Second element info
will be the data frame provided
to the function, filtered to the row matching the successfully logged in username.
When user_auth
is FALSE info
is NULL.
Shiny authentication module for use with loginUI
-Call via shiny::callModule(shinyauthr::login, "id", ...)
This function is now deprecated in favour of loginServer which uses shiny's new moduleServer -method as opposed to the callModule method used by this function. -See the loginServer documentation For details on how to migrate.
- -+if (FALSE) { -user_credentials <- shiny::callModule( - login, - id = "login", - data = user_base, - user_col = user, - pwd_col = password, - log_out = reactive(logout_init()) -) -} - -
Shiny authentication module for use with loginUI
+Call via shiny::callModule(shinyauthr::login, "id", ...)
This function is now deprecated in favour of loginServer which uses shiny's new moduleServer +method as opposed to the callModule method used by this function. +See the loginServer documentation For details on how to migrate.
+if (FALSE) {
+user_credentials <- shiny::callModule(
+ login,
+ id = "login",
+ data = user_base,
+ user_col = user,
+ pwd_col = password,
+ log_out = reactive(logout_init())
+)
+}
+
+
Developed by Paul Campbell.
+Developed by Paul Campbell.
Shiny authentication module for use with loginUI
+Shiny authentication module for use with loginUI
loginServer( - id, - data, - user_col, - pwd_col, - sodium_hashed = FALSE, - log_out = shiny::reactiveVal(), - reload_on_logout = FALSE, - cookie_logins = FALSE, - sessionid_col, - cookie_getter, - cookie_setter -)- -
id | -An ID string that corresponds with the ID used to call the module's UI function |
-
---|---|
data | -data frame or tibble containing user names, passwords and other user data |
-
user_col | -bare (unquoted) or quoted column name containing user names |
-
pwd_col | -bare (unquoted) or quoted column name containing passwords |
-
sodium_hashed | -have the passwords been hash encrypted using the sodium package? defaults to FALSE |
-
log_out | -[reactive] supply the returned reactive from logoutServer here to trigger a user logout |
-
reload_on_logout | -should app force a session reload on logout? |
-
cookie_logins | -enable automatic logins via browser cookies? |
-
sessionid_col | -bare (unquoted) or quoted column name containing session ids |
-
cookie_getter | -a function that returns a data.frame with at least two columns: user and session |
-
cookie_setter | -a function with two parameters: user and session. The function must save these to a database. |
-
loginServer(
+ id,
+ data,
+ user_col,
+ pwd_col,
+ sodium_hashed = FALSE,
+ log_out = shiny::reactiveVal(),
+ reload_on_logout = FALSE,
+ cookie_logins = FALSE,
+ sessionid_col,
+ cookie_getter,
+ cookie_setter
+)
An ID string that corresponds with the ID used to call the module's UI function
data frame or tibble containing user names, passwords and other user data
bare (unquoted) or quoted column name containing user names
bare (unquoted) or quoted column name containing passwords
have the passwords been hash encrypted using the sodium package? defaults to FALSE
[reactive] supply the returned reactive from logoutServer here to trigger a user logout
should app force a session reload on logout?
enable automatic logins via browser cookies?
bare (unquoted) or quoted column name containing session ids
a function that returns a data.frame with at least two columns: user and session
a function with two parameters: user and session. The function must save these to a database.
The module will return a reactive 2 element list to your main application.
First element user_auth
is a boolean indicating whether there has been
a successful login or not. Second element info
will be the data frame provided
to the function, filtered to the row matching the successfully logged in username.
When user_auth
is FALSE info
is NULL.
This module uses shiny's new moduleServer method as opposed to the callModule -method used by the now deprecated login function and must be called differently in your app. +
This module uses shiny's new moduleServer method as opposed to the callModule +method used by the now deprecated login function and must be called differently in your app. For details on how to migrate see the 'Migrating from callModule to moduleServer' section of -Modularizing Shiny app code.
- -#> -#> Attaching package: ‘shiny’#> The following object is masked from ‘package:shinyauthr’: -#> -#> runExample-# dataframe that holds usernames, passwords and other user data -user_base <- dplyr::tibble( - user = c("user1", "user2"), - password = c("pass1", "pass2"), - permissions = c("admin", "standard"), - name = c("User One", "User Two") -) - -ui <- fluidPage( - # add logout button UI - div(class = "pull-right", shinyauthr::logoutUI(id = "logout")), - # add login panel UI function - shinyauthr::loginUI(id = "login"), - # setup table output to show user info after login - tableOutput("user_table") -) - -server <- function(input, output, session) { - # call login module supplying data frame, - # user and password cols and reactive trigger - credentials <- shinyauthr::loginServer( - id = "login", - data = user_base, - user_col = user, - pwd_col = password, - log_out = reactive(logout_init()) - ) - - # call the logout module with reactive trigger to hide/show - logout_init <- shinyauthr::logoutServer( - id = "logout", - active = reactive(credentials()$user_auth) - ) - - output$user_table <- renderTable({ - # use req to only render results when credentials()$user_auth is TRUE - req(credentials()$user_auth) - credentials()$info - }) -} +Modularizing Shiny app code. +-if (interactive()) shinyApp(ui = ui, server = server) -
library(shiny)
+#>
+#> Attaching package: ‘shiny’
+#> The following object is masked from ‘package:shinyauthr’:
+#>
+#> runExample
+
+# dataframe that holds usernames, passwords and other user data
+user_base <- dplyr::tibble(
+ user = c("user1", "user2"),
+ password = c("pass1", "pass2"),
+ permissions = c("admin", "standard"),
+ name = c("User One", "User Two")
+)
+
+ui <- fluidPage(
+ # add logout button UI
+ div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
+ # add login panel UI function
+ shinyauthr::loginUI(id = "login"),
+ # setup table output to show user info after login
+ tableOutput("user_table")
+)
+
+server <- function(input, output, session) {
+ # call login module supplying data frame,
+ # user and password cols and reactive trigger
+ credentials <- shinyauthr::loginServer(
+ id = "login",
+ data = user_base,
+ user_col = user,
+ pwd_col = password,
+ log_out = reactive(logout_init())
+ )
+
+ # call the logout module with reactive trigger to hide/show
+ logout_init <- shinyauthr::logoutServer(
+ id = "logout",
+ active = reactive(credentials()$user_auth)
+ )
+
+ output$user_table <- renderTable({
+ # use req to only render results when credentials()$user_auth is TRUE
+ req(credentials()$user_auth)
+ credentials()$info
+ })
+}
+
+if (interactive()) shinyApp(ui = ui, server = server)
+
Developed by Paul Campbell.
+Developed by Paul Campbell.
Shiny UI Module for use with loginServer
+Shiny UI Module for use with loginServer
loginUI( - id, - title = "Please log in", - user_title = "User Name", - pass_title = "Password", - login_title = "Log in", - error_message = "Invalid username or password!", - additional_ui = NULL, - cookie_expiry = 7 -)- -
id | -An ID string that corresponds with the ID used to call the module's server function |
-
---|---|
title | -header title for the login panel |
-
user_title | -label for the user name text input |
-
pass_title | -label for the password text input |
-
login_title | -label for the login button |
-
error_message | -message to display after failed login |
-
additional_ui | -additional shiny UI element(s) to add below login button. Wrap multiple inside |
-
cookie_expiry | -number of days to request browser to retain login cookie |
-
loginUI(
+ id,
+ title = "Please log in",
+ user_title = "User Name",
+ pass_title = "Password",
+ login_title = "Log in",
+ login_btn_class = "btn-primary",
+ error_message = "Invalid username or password!",
+ additional_ui = NULL,
+ cookie_expiry = 7
+)
An ID string that corresponds with the ID used to call the module's server function
header title for the login panel
label for the user name text input
label for the password text input
label for the login button
bootstrap class for the login button. defaults to "btn-primary"
message to display after failed login
additional shiny UI element(s) to add below login button. Wrap multiple inside shiny::tagList()
number of days to request browser to retain login cookie
Shiny UI login panel with user name text input, password text input and login action button.
++library(shiny) - -# dataframe that holds usernames, passwords and other user data -user_base <- dplyr::tibble( - user = c("user1", "user2"), - password = c("pass1", "pass2"), - permissions = c("admin", "standard"), - name = c("User One", "User Two") -) - -ui <- fluidPage( - # add logout button UI - div(class = "pull-right", shinyauthr::logoutUI(id = "logout")), - # add login panel UI function - shinyauthr::loginUI(id = "login"), - # setup table output to show user info after login - tableOutput("user_table") -) - -server <- function(input, output, session) { - # call login module supplying data frame, - # user and password cols and reactive trigger - credentials <- shinyauthr::loginServer( - id = "login", - data = user_base, - user_col = user, - pwd_col = password, - log_out = reactive(logout_init()) - ) - - # call the logout module with reactive trigger to hide/show - logout_init <- shinyauthr::logoutServer( - id = "logout", - active = reactive(credentials()$user_auth) - ) - - output$user_table <- renderTable({ - # use req to only render results when credentials()$user_auth is TRUE - req(credentials()$user_auth) - credentials()$info - }) -} - -if (interactive()) shinyApp(ui = ui, server = server) -
library(shiny)
+
+# dataframe that holds usernames, passwords and other user data
+user_base <- dplyr::tibble(
+ user = c("user1", "user2"),
+ password = c("pass1", "pass2"),
+ permissions = c("admin", "standard"),
+ name = c("User One", "User Two")
+)
+
+ui <- fluidPage(
+ # add logout button UI
+ div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
+ # add login panel UI function
+ shinyauthr::loginUI(id = "login"),
+ # setup table output to show user info after login
+ tableOutput("user_table")
+)
+
+server <- function(input, output, session) {
+ # call login module supplying data frame,
+ # user and password cols and reactive trigger
+ credentials <- shinyauthr::loginServer(
+ id = "login",
+ data = user_base,
+ user_col = user,
+ pwd_col = password,
+ log_out = reactive(logout_init())
+ )
+
+ # call the logout module with reactive trigger to hide/show
+ logout_init <- shinyauthr::logoutServer(
+ id = "logout",
+ active = reactive(credentials()$user_auth)
+ )
+
+ output$user_table <- renderTable({
+ # use req to only render results when credentials()$user_auth is TRUE
+ req(credentials()$user_auth)
+ credentials()$info
+ })
+}
+
+if (interactive()) shinyApp(ui = ui, server = server)
+
Developed by Paul Campbell.
+Developed by Paul Campbell.
Deprecated. Use logoutServer instead.
+Deprecated. Use logoutServer instead.
input | -shiny input |
-
---|---|
output | -shiny output |
-
session | -shiny session |
-
active | -[reactive] supply the returned |
-
shiny input
shiny output
shiny session
[reactive] supply the returned user_auth
boolean reactive from login
+here to hide/show the logout button
Reactive boolean, to be supplied as the log_out
argument of the
- login module to trigger the logout process
Shiny authentication module for use with logoutUI
-Call via shiny::callModule(shinyauthr::logout, "id", ...)
This function is now deprecated in favour of logoutServer which uses shiny's new moduleServer -method as opposed to the callModule method used by this function. -See the logoutServer documentation For details on how to migrate.
- -+login module to trigger the logout process +if (FALSE) { -logout_init <- shiny::callModule( - logout, - id = "logout", - active = reactive(user_credentials()$user_auth) -) -} - -
Shiny authentication module for use with logoutUI
+Call via shiny::callModule(shinyauthr::logout, "id", ...)
This function is now deprecated in favour of logoutServer which uses shiny's new moduleServer +method as opposed to the callModule method used by this function. +See the logoutServer documentation For details on how to migrate.
+if (FALSE) {
+logout_init <- shiny::callModule(
+ logout,
+ id = "logout",
+ active = reactive(user_credentials()$user_auth)
+)
+}
+
+
Developed by Paul Campbell.
+Developed by Paul Campbell.
Shiny authentication module for use with logoutUI
+Shiny authentication module for use with logoutUI
logoutServer(id, active, ...)- -
id | -An ID string that corresponds with the ID used to call the module's UI function |
-
---|---|
active | -
|
-
... | -arguments passed to toggle |
-
logoutServer(id, active, ...)
An ID string that corresponds with the ID used to call the module's UI function
reactive
supply the returned user_auth
boolean reactive from loginServer
+here to hide/show the logout button
arguments passed to toggle
Reactive boolean, to be supplied as the log_out
argument of the
- loginServer module to trigger the logout process
This module uses shiny's new moduleServer method as opposed to the callModule -method used by the now deprecated login function and must be called differently in your app. +loginServer module to trigger the logout process
+This module uses shiny's new moduleServer method as opposed to the callModule +method used by the now deprecated login function and must be called differently in your app. For details on how to migrate see the 'Migrating from callModule to moduleServer' section of -Modularizing Shiny app code.
- -+Modularizing Shiny app code. +library(shiny) - -# dataframe that holds usernames, passwords and other user data -user_base <- dplyr::tibble( - user = c("user1", "user2"), - password = c("pass1", "pass2"), - permissions = c("admin", "standard"), - name = c("User One", "User Two") -) - -ui <- fluidPage( - # add logout button UI - div(class = "pull-right", shinyauthr::logoutUI(id = "logout")), - # add login panel UI function - shinyauthr::loginUI(id = "login"), - # setup table output to show user info after login - tableOutput("user_table") -) - -server <- function(input, output, session) { - # call login module supplying data frame, - # user and password cols and reactive trigger - credentials <- shinyauthr::loginServer( - id = "login", - data = user_base, - user_col = user, - pwd_col = password, - log_out = reactive(logout_init()) - ) - - # call the logout module with reactive trigger to hide/show - logout_init <- shinyauthr::logoutServer( - id = "logout", - active = reactive(credentials()$user_auth) - ) - - output$user_table <- renderTable({ - # use req to only render results when credentials()$user_auth is TRUE - req(credentials()$user_auth) - credentials()$info - }) -} - -if (interactive()) shinyApp(ui = ui, server = server) -
library(shiny)
+
+# dataframe that holds usernames, passwords and other user data
+user_base <- dplyr::tibble(
+ user = c("user1", "user2"),
+ password = c("pass1", "pass2"),
+ permissions = c("admin", "standard"),
+ name = c("User One", "User Two")
+)
+
+ui <- fluidPage(
+ # add logout button UI
+ div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
+ # add login panel UI function
+ shinyauthr::loginUI(id = "login"),
+ # setup table output to show user info after login
+ tableOutput("user_table")
+)
+
+server <- function(input, output, session) {
+ # call login module supplying data frame,
+ # user and password cols and reactive trigger
+ credentials <- shinyauthr::loginServer(
+ id = "login",
+ data = user_base,
+ user_col = user,
+ pwd_col = password,
+ log_out = reactive(logout_init())
+ )
+
+ # call the logout module with reactive trigger to hide/show
+ logout_init <- shinyauthr::logoutServer(
+ id = "logout",
+ active = reactive(credentials()$user_auth)
+ )
+
+ output$user_table <- renderTable({
+ # use req to only render results when credentials()$user_auth is TRUE
+ req(credentials()$user_auth)
+ credentials()$info
+ })
+}
+
+if (interactive()) shinyApp(ui = ui, server = server)
+
Developed by Paul Campbell.
+Developed by Paul Campbell.
Shiny UI Module for use with logoutServer
+Shiny UI Module for use with logoutServer
logoutUI( - id, - label = "Log out", - icon = NULL, - class = "btn-danger", - style = "color: white;" -)- -
id | -An ID string that corresponds with the ID used to call the module's server function |
-
---|---|
label | -label for the logout button |
-
icon | -An optional |
-
class | -bootstrap class for the logout button |
-
style | -css styling for the logout button |
-
logoutUI(
+ id,
+ label = "Log out",
+ icon = NULL,
+ class = "btn-danger",
+ style = "color: white;"
+)
An ID string that corresponds with the ID used to call the module's server function
label for the logout button
An optional icon
to appear on the button.
bootstrap class for the logout button
css styling for the logout button
Shiny UI action button
++library(shiny) - -# dataframe that holds usernames, passwords and other user data -user_base <- dplyr::tibble( - user = c("user1", "user2"), - password = c("pass1", "pass2"), - permissions = c("admin", "standard"), - name = c("User One", "User Two") -) - -ui <- fluidPage( - # add logout button UI - div(class = "pull-right", shinyauthr::logoutUI(id = "logout")), - # add login panel UI function - shinyauthr::loginUI(id = "login"), - # setup table output to show user info after login - tableOutput("user_table") -) - -server <- function(input, output, session) { - # call login module supplying data frame, - # user and password cols and reactive trigger - credentials <- shinyauthr::loginServer( - id = "login", - data = user_base, - user_col = user, - pwd_col = password, - log_out = reactive(logout_init()) - ) - - # call the logout module with reactive trigger to hide/show - logout_init <- shinyauthr::logoutServer( - id = "logout", - active = reactive(credentials()$user_auth) - ) - - output$user_table <- renderTable({ - # use req to only render results when credentials()$user_auth is TRUE - req(credentials()$user_auth) - credentials()$info - }) -} - -if (interactive()) shinyApp(ui = ui, server = server) -
library(shiny)
+
+# dataframe that holds usernames, passwords and other user data
+user_base <- dplyr::tibble(
+ user = c("user1", "user2"),
+ password = c("pass1", "pass2"),
+ permissions = c("admin", "standard"),
+ name = c("User One", "User Two")
+)
+
+ui <- fluidPage(
+ # add logout button UI
+ div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
+ # add login panel UI function
+ shinyauthr::loginUI(id = "login"),
+ # setup table output to show user info after login
+ tableOutput("user_table")
+)
+
+server <- function(input, output, session) {
+ # call login module supplying data frame,
+ # user and password cols and reactive trigger
+ credentials <- shinyauthr::loginServer(
+ id = "login",
+ data = user_base,
+ user_col = user,
+ pwd_col = password,
+ log_out = reactive(logout_init())
+ )
+
+ # call the logout module with reactive trigger to hide/show
+ logout_init <- shinyauthr::logoutServer(
+ id = "logout",
+ active = reactive(credentials()$user_auth)
+ )
+
+ output$user_table <- renderTable({
+ # use req to only render results when credentials()$user_auth is TRUE
+ req(credentials()$user_auth)
+ credentials()$info
+ })
+}
+
+if (interactive()) shinyApp(ui = ui, server = server)
+
Developed by Paul Campbell.
+Developed by Paul Campbell.
This function is used to generate random session ids.
-randomString(n = 64)- -
n | -length of string |
-
---|
A random character string.
- -Developed by Paul Campbell.
-Site built with pkgdown 1.6.1.
-runExample(example = c("basic", "shinydashboard", "navbarPage"))- -
example | -The app to launch. Options are "basic", "shinydashboard" or "navbarPage" |
-
---|
runExample(example = c("basic", "shinydashboard", "navbarPage"))
The app to launch. Options are "basic", "shinydashboard" or "navbarPage"
No return value, a shiny app is launched.
++## Only run this example in interactive R sessions -if (interactive()) { - runExample("basic") - runExample("shinydashboard") - runExample("navbarPage") -} -
## Only run this example in interactive R sessions
+if (interactive()) {
+ runExample("basic")
+ runExample("shinydashboard")
+ runExample("navbarPage")
+}
+
Developed by Paul Campbell.
+Developed by Paul Campbell.
Launch example shiny navbarPage app using shinyauthr authentication modules
-runNavbarPageExample()- - - -
Developed by Paul Campbell.
-Site built with pkgdown 1.6.1.
-Launch example shinydashboard using shinyauthr authentication modules
-runShinyDashboardExample()- - - -
Developed by Paul Campbell.
-Site built with pkgdown 1.6.1.
-Launch example shiny dashboard using shinyauthr authentication modules
-runShinyExample()- - -
Paul Campbell, pacampbell91@gmail.com
- -Developed by Paul Campbell.
-Site built with pkgdown 1.6.1.
-