Testing of shiny modules with other modules

In a large Shiny App, I have a lot of modules with other modules within. These nested modules also sometimes have input, like e.g. buttons. The following example is a MWE for this problem. How can I test summaryServer and simulate a click or other Input within rangeServer?

summaryUI <- function(id) {
  tagList(
    textOutput(NS(id, "min")),
    textOutput(NS(id, "mean")),
    textOutput(NS(id, "max")),
    rangeUI(NS(id, "range"))
  )
}
summaryServer <- function(id, var) {
  stopifnot(is.reactive(var))
  
  moduleServer(id, function(input, output, session) {
  
    d_act = reactiveVal("Haha nope")
    range_val = rangeServer("range", var = var)
    
    # waits to range_val
    observeEvent(range_val(),{
      d_act("TRUE")
      message(range_val())
      output$min <- renderText(range_val()[[1]])
      output$max <- renderText(range_val()[[2]])
      output$mean <- renderText(mean(var()))
    })
  })
}

rangeUI = function(id) {
  textInput(inputId = NS(id, "go"),label = "Go")
}
rangeServer = function(id, var){
  moduleServer(id, function(input, output, session){
   # when button gets clicked
    eventReactive(input$go,{
      range(var(), na.rm = TRUE)
      
    },ignoreInit = TRUE, ignoreNULL = TRUE)
  })
}

library(shiny)

ui <- fluidPage(
  summaryUI("sum")
)

server <- function(input, output, session) {
  x = reactiveVal(1:10)
  summaryServer("sum", x)
}

shinyApp(ui, server)

x <- reactiveVal(1:10)
testServer(summaryServer, args = list(var = x), {

  cat("var active?", d_act(),"\n")
  # How to call/set "go" here?

  
  cat("var active?", d_act(),"\n")
})

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.