Skip to content

Commit

Permalink
Fix log_shiny_input_changes (#100)
Browse files Browse the repository at this point in the history
# 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 <[email protected]>
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 <[email protected]>
  • Loading branch information
3 people authored Nov 7, 2024
1 parent 4728b9b commit bce9fd0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions R/log_shiny_input_changes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#' })
#' }
#'
Expand All @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion man/log_shiny_input_changes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bce9fd0

Please sign in to comment.