From bce9fd00599fd5e7bad973f4cac552a8948c09ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= <185338939+llrs-roche@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:44:52 +0100 Subject: [PATCH] Fix log_shiny_input_changes (#100) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Pull Request This fixes the shiny app and also `log_shiny_input_changes` works now without error. I took the liberty to "fix" and accept lower case teal.log_level, but I'm not sure if this is wanted or not. At least it could provide an informative error message if a lower case is not accepted. Last, I see this logging: ``` TRACE from teal.logger [2024-11-06 13:34:17] :: character(0) Shiny input change detected in "foo": "foo" -> "fooa" ``` Note the `character(0)`, this is "{ns}"; but I don't see any assignment besides [making it 0 on line 54](https://github.com/insightsengineering/teal.logger/blob/cd9cc7e5be19c2417700308d6bdf1d8c4a55966d/R/log_shiny_input_changes.R#L54). So I am not sure if this should be replaced on the logger environment or here, but either case it could be more informative. Fixes #98 --------- Signed-off-by: Lluís Revilla <185338939+llrs-roche@users.noreply.github.com> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Dawid Kałędkowski --- R/log_shiny_input_changes.R | 9 ++++++--- man/log_shiny_input_changes.Rd | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index bb43cc0..5f6ad0e 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -27,7 +27,7 @@ #' log_shiny_input_changes(input, excluded_inputs = "password", excluded_pattern = "mean") #' #' output$plot <- renderPlot({ -#' hist(rnorm(1e3, input$mean, input$sd), main = input$title) +#' hist(rnorm(1e3, input$mean1, input$sd), main = input$title) #' }) #' } #' @@ -44,9 +44,12 @@ log_shiny_input_changes <- function( stopifnot(is.character(namespace) && length(namespace) == 1) stopifnot(is.character(excluded_inputs)) stopifnot(is.character(excluded_pattern) && length(excluded_pattern) == 1) - stopifnot(inherits(session, "session_proxy")) + stopifnot(inherits(session, "session_proxy") || inherits(session, "ShinySession")) - if (logger::TRACE > logger::as.loglevel(get_val("TEAL.LOG_LEVEL", "teal.log_level", "INFO"))) { + # Log even if written in lower case or numeric values + log_level <- get_val("TEAL.LOG_LEVEL", "teal.log_level", "INFO") + if (!is.numeric(log_level)) log_level <- toupper(log_level) + if (logger::TRACE > logger::as.loglevel(log_level)) { # to avoid setting observers when not needed return(invisible(NULL)) } diff --git a/man/log_shiny_input_changes.Rd b/man/log_shiny_input_changes.Rd index 148557f..f28fe96 100644 --- a/man/log_shiny_input_changes.Rd +++ b/man/log_shiny_input_changes.Rd @@ -47,7 +47,7 @@ server <- function(input, output) { log_shiny_input_changes(input, excluded_inputs = "password", excluded_pattern = "mean") output$plot <- renderPlot({ - hist(rnorm(1e3, input$mean, input$sd), main = input$title) + hist(rnorm(1e3, input$mean1, input$sd), main = input$title) }) }