R 如何将其转换为一个闪亮的模块

R 如何将其转换为一个闪亮的模块,r,shiny,R,Shiny,您能提供一个使用renderUI的模块化闪亮代码的MWE吗?我想举个例子 这里有一个很好的教程讨论了这一点:但是,它没有显示如何在ui或服务器中集成renderUI组件的模块化 以下是我迄今为止所尝试的: 在我的ui代码中,我有: htmlOutput("selectionUI") output$selectionUI <- renderUI({ req(input$Filter) selectInput( inputId = "Selection",

您能提供一个使用renderUI的模块化闪亮代码的MWE吗?我想举个例子

这里有一个很好的教程讨论了这一点:但是,它没有显示如何在ui或服务器中集成renderUI组件的模块化

以下是我迄今为止所尝试的:

在我的ui代码中,我有:

  htmlOutput("selectionUI")
  output$selectionUI <- renderUI({
    req(input$Filter)
    selectInput(
      inputId = "Selection",
      label = "Selection",
      choices = get("qlist", envir = get(input$source))[[input$Filter]]$responses)
  })
在我的服务器代码中,我有:

  htmlOutput("selectionUI")
  output$selectionUI <- renderUI({
    req(input$Filter)
    selectInput(
      inputId = "Selection",
      label = "Selection",
      choices = get("qlist", envir = get(input$source))[[input$Filter]]$responses)
  })

可能是这样的。因为我没有你的数据,所以我没有测试过

library(shiny)

ui <- fluidPage(
  h1("Get me a Module!"),
  selectInput("source", "Some source", choices = letters[1:4]),
  selectInput("filter", "Some filter", choices = letters[1:4]),
  selectionChooserUI("id_of_me")
)

server <- function(input, output, session) {
  get_me_choices <- reactive({
    get("qlist", envir = get(req(input$source)))[[req(input$filter)]]$responses })

  callModule(module = selectionChooser, id = "id_of_me", choices = get_me_choices)
}

selectionChooserUI <- function(id) {
  ns <- NS(id)
  uiOutput(ns('selection'))
}

selectionChooser <- function(input, output, session, choices) {
  ns <- session$ns

  output$selection <- renderUI({
    selectInput(
      inputId = ns('selection'),
      label = 'Selection',
      choices = choices
    )
  })
}
库(闪亮)

您在
selectionChooserUI
中将
输出命名为
控件的ui。所以它应该是
selectionChooser
上的
output$controls
。我认为您应该使用
filter()
而不是
input$filter
input[[filter()]]
。谢谢@user5029763我做了这些更改,并导致了相同的错误<代码>错误:缺少参数“output”,没有默认值
如何在服务器端调用?检查
callModule
我已经更新了我的问题,以便更清楚地了解我在寻找什么。如果你知道如何构建模块化renderUI的MWE,请将其作为答案提交,我很乐意接受。这对你的应用程序模块化有帮助吗?