shiny:testServer()
looks amazing and I'm really looking forward to using it in my apps, so thank you to everyone who developed it.
I don't yet understand, though, how to provide an input arg that is itself a reactive. My use case looks something like this (although the real app is a bit more complicated):
First, a module for triggering some actions in other modules. This needs to be its own module, not a run button embedded in one module, since it interacts with several modules. It is also completely separate, visually, from the parts of the page used by the other modules.
## Module for triggering run/reveal menu action in several other modules
mod_run_ui <- function(id){
ns <- NS(id)
tagList(
actionButton(inputId = ns("run"),
label = "MAKE IT HAPPEN!"),
HTML("</br></br>")
)
}
mod_run_server <- function(input, output, session) {
run_update <- reactive({
return(input$run)
})
return(list(run_update = run_update))
}
I also have a module that uses requires input from other modules (here I'm simplifying it to requiring only one, from the run module above, but in reality it uses more).
## Module for running a model after the "run" module says it's time
mod_calc_ui <- function(id){
ns <- NS(id)
tagList(
## Some graphs and downloadable reports based on the model running
)
}
mod_calc_server <- function(input, output, run_status) {
## Some model calculations
}
The app server then looks like this:
run_model <- callModule(mod_run_server, id = "run_models")
model1_results <- callModule(mod_calc_server, id = "model1_results", run_status = run_model$run_update)
So, in order to test mod_calc_server()
, I need to provide a reactive as the argument for run_status
. I understand that I can pass arguments for a module to testServer using the args
parameter, but I'm not sure how to do this when the argument needs to be a reactive itself. Here is the example from this documentation, but since testServer()
is called outside of a reactive context (I think), I don't know how to provide it with a reactive argument.
testServer(myModule2, args = list(multiplier = 3), {
session$setInputs(x = 1)
expect_equal(myreactive(), 3)
})