From 7873f9463bcc2f9802e77816f1a77af7773ec3c3 Mon Sep 17 00:00:00 2001 From: Gerhard Burger Date: Thu, 15 Dec 2022 16:22:03 +0100 Subject: [PATCH 1/2] Allow reactive user data --- R/login.R | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/R/login.R b/R/login.R index 145e67c..616d58e 100644 --- a/R/login.R +++ b/R/login.R @@ -121,8 +121,12 @@ loginServer <- function(id, } } - # ensure all text columns are character class - data <- dplyr::mutate_if(data, is.factor, as.character) + data_reactive <- reactive({ + # if not already reactive, make data reactive + data_temp <- if(is.reactive(data)) data else reactive(data) + # ensure all text columns are character class + dplyr::mutate_if(data_temp(), is.factor, as.character) + }) shiny::moduleServer( id, @@ -191,7 +195,7 @@ loginServer <- function(id, credentials$user_auth <- TRUE credentials$info <- dplyr::bind_cols( - dplyr::filter(data, {{user_col}} == .userid), + dplyr::filter(data_reactive(), {{user_col}} == .userid), dplyr::select(cookie_data, -{{user_col}}) ) } @@ -203,10 +207,10 @@ loginServer <- function(id, shiny::observeEvent(input$button, { # check for match of input username to username column in data - row_username <- which(dplyr::pull(data, {{user_col}}) == input$user_name) + row_username <- which(dplyr::pull(data_reactive(), {{user_col}}) == input$user_name) if (length(row_username)) { - row_password <- dplyr::filter(data, dplyr::row_number() == row_username) + row_password <- dplyr::filter(data_reactive(), dplyr::row_number() == row_username) row_password <- dplyr::pull(row_password, {{pwd_col}}) if (sodium_hashed) { password_match <- sodium::password_verify(row_password, input$password) @@ -221,7 +225,7 @@ loginServer <- function(id, if (length(row_username) == 1 && password_match) { credentials$user_auth <- TRUE - credentials$info <- dplyr::filter(data, {{user_col}} == input$user_name) + credentials$info <- dplyr::filter(data_reactive(), {{user_col}} == input$user_name) if (cookie_logins) { .sessionid <- randomString() From 3c633990a0de6227dffcd1af25733801cbcb7941 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 29 Feb 2024 17:46:40 +0100 Subject: [PATCH 2/2] fully qualify shiny function calls and document change --- DESCRIPTION | 2 +- R/login.R | 7 ++++--- man/loginServer.Rd | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a458526..b46fcb0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,7 +34,7 @@ Suggests: knitr, rmarkdown, covr -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 URL: https://github.com/paulc91/shinyauthr BugReports: https://github.com/paulc91/shinyauthr/issues Config/testthat/edition: 3 diff --git a/R/login.R b/R/login.R index 616d58e..766e6f8 100644 --- a/R/login.R +++ b/R/login.R @@ -68,7 +68,8 @@ loginUI <- function(id, #' \href{https://shiny.rstudio.com/articles/modules.html}{Modularizing Shiny app code}. #' #' @param id An ID string that corresponds with the ID used to call the module's UI function -#' @param data data frame or tibble containing user names, passwords and other user data +#' @param data data frame or tibble containing user names, passwords and other user data. Can be either +#' a static object or a shiny \link[shiny]{reactive} object #' @param user_col bare (unquoted) or quoted column name containing user names #' @param pwd_col bare (unquoted) or quoted column name containing passwords #' @param sodium_hashed have the passwords been hash encrypted using the sodium package? defaults to FALSE @@ -121,9 +122,9 @@ loginServer <- function(id, } } - data_reactive <- reactive({ + data_reactive <- shiny::reactive({ # if not already reactive, make data reactive - data_temp <- if(is.reactive(data)) data else reactive(data) + data_temp <- if (shiny::is.reactive(data)) data else shiny::reactive(data) # ensure all text columns are character class dplyr::mutate_if(data_temp(), is.factor, as.character) }) diff --git a/man/loginServer.Rd b/man/loginServer.Rd index dd54211..34752d4 100644 --- a/man/loginServer.Rd +++ b/man/loginServer.Rd @@ -21,7 +21,8 @@ loginServer( \arguments{ \item{id}{An ID string that corresponds with the ID used to call the module's UI function} -\item{data}{data frame or tibble containing user names, passwords and other user data} +\item{data}{data frame or tibble containing user names, passwords and other user data. Can be either +a static object or a shiny \link[shiny]{reactive} object} \item{user_col}{bare (unquoted) or quoted column name containing user names}