Closed m7pr closed 2 months ago
CCing @daroczig for visibility
Thanks a ton, looks very promising! Could you please take a look at the failing unit tests?
@daroczig sure, just made one change, can you approve workflows to run again?
CC @daroczig sure, just made one change, can you approve workflows to run again?
sorry for the delay with getting back to this :facepalm:
I've rerun the unit tests, but seeing the same error:
── Failure ('test-CRANSKIP-hooks.R:101:5'): shiny input change is logged with different level ──
`obs` does not match "ERROR \\[[0-9: \\-]+\\] Shiny input change detected on a: NULL -> 2".
Actual value: "INFO \[2024-07-31 21:49:35\] Loading required package: shiny\\nLoading required package: shiny\\nERROR \[2024-07-31 21:49:36\] mock-session Default Shiny inputs initialized: \{\}\\nERROR \[2024-07-31 21:49:36\] mock-session Shiny input change detected in a: NULL -> 2"
can you please update the related unit test(s)?
Sorry @daroczig for the delay. I fixed the mentioned test.
since then, we switched using snapshots for testing, so that's causing some git conflict -- I'm looking into it
Alternative approach for https://github.com/daroczig/logger/pull/154
Usage in tests
We enhanced
log_shiny_input_changes
so that it usessession
object. This allows to detect if we are in the Mocked Shiny session - a type of the session used inshiny::testServer
during{testthat}
tests. This is needed so that tests usingshiny::testServer
do not fail due to:Distinction between modules
The ability of using
session
object allows to extract the current module's namespace. This is useful for logging, if you have multiple modules with the same input names. This way you can distinguish log-messages based on modules' namespaces.Shiny App Code
```r # Define the UI for a module counterUI <- function(id, label = "Counter") { ns <- NS(id) tagList( actionButton(ns("button"), label = label), verbatimTextOutput(ns("out")) ) } # Define the server logic for a module counterServer <- function(id) { moduleServer( id, function(input, output, session) { logger::log_shiny_input_changes(input) count <- reactiveVal(0) observeEvent(input$button, { count(count() + 1) }) output$out <- renderText({ count() }) count } ) } # Use the module in an app ui <- fluidPage( counterUI("counter1", "Counter #1"), counterUI("counter2", "Counter #2") ) server <- function(input, output, session) { counterServer("counter1") counterServer("counter2") } if (interactive()) { shinyApp(ui, server) } ```Output