测试模块化 R Shiny (golem) 仪表板

问题描述

我一直在探索(**并且喜欢)使用 R Shiny 开发模块化仪表板的 golem 包。但我正在努力思考如何测试模块化仪表板。

例如在下面的 repex 中,如果导入模块中的 input$n_rows 设置为 15,我将如何测试显示模块中的输出包含 15 行?

如果您对此提供任何支持,我将不胜感激!


library(shiny)
library(reactable)
library(dplyr)

# Import module UI
mod_import_ui <- function(id){
  
  ns <- NS(id)
  
  fluidRow(
    # Allow the user to select the number of rows to view
    numericInput(ns("n_rows"),"Select number of observations",value = 10)
    
  )
}

# Import module Server
mod_import_server <- function(id){
  
  moduleServer(
    id,function(input,output,session){
      
      data <- reactive({
        
        # Sample the requested number of rows from mtcars and return this to the application server
        mtcars %>%
          slice_sample(n = input$n_rows)
        # [....] # Some complex formatting and transformations
        
      })
      
      return(data)
      
      
      
    }
  )}

# Display module UI
mod_display_ui <- function(id){
  
  ns <- NS(id)
  
  fluidRow(
    
    reactableOutput(ns("table"))
    
  )
}

# Display module Server
mod_display_server <- function(id,data_in){
  
  moduleServer(
    id,session){
      
      # [....] # Some more transformations and merging with data from other modules
      
      output$table <- renderReactable(reactable(data_in()))
      
    }
  )}


app_ui <- function(request) { 
  
  tagList(
  
    mod_import_ui("import_1"),mod_display_ui("display_1")

  )
  
  }


app_server <- function(input,session) { 
  
  data_in <- mod_import_server("import_1")
  mod_display_server("display_1",data_in)
  
}

shinyApp(ui = app_ui,server = app_server)


解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)