闪亮的模块selectInput不起作用

时间:2018-09-04 19:59:21

标签: r input module shiny

由于某种原因,在模块中使用selectInput对输入值的更改没有反应。我添加了一个最小的示例来演示我的问题。如果我在没有模块的情况下编写了相同的代码,即将模块的ui和服务器代码粘贴到主服务器上,则没有命名空间功能的ui函数可以正常工作。 我的代码没有真正看到此问题。

require(shiny)

ui <- function(){
    dummyUI("test")
}

server <- function(input, output, session) {

    callModule(dummy, "test")
}

dummyUI <- function(id) {
    ns <-NS(id)
    uiOutput(width = 6, ns("selectMaterial"))
}

dummy <- function(input, output, session) {
    # render UI for the filters
    output$selectMaterial <- renderUI({
        selectInput(
            inputId = "selectMaterial",
            label = "Choose Materials" ,
            choices = c("a","b"),
            multiple = TRUE)
    })

    observeEvent(input$selectMaterial ,{print("hi")})
}

shinyApp(ui(), server)

1 个答案:

答案 0 :(得分:0)

this article(在“在模块中使用renderUI ”),则需要使用renderUI中的名称空间功能。

require(shiny)

ui <- function(){
  dummyUI("test")
}

server <- function(input, output, session) {

  callModule(dummy, "test")
}

dummyUI <- function(id) {
  ns <-NS(id)
  uiOutput(width = 6, ns("selectMaterial"))
}

dummy <- function(input, output, session) {
  # render UI for the filters
  output$selectMaterial <- renderUI({
    selectInput(
      inputId = session$ns("selectMaterial"),       ## <= namespace here
      label = "Choose Materials" ,
      choices = c("a","b"),
      multiple = TRUE)
  })

  observeEvent(input$selectMaterial ,{print("hi")})
}

shinyApp(ui(), server)
相关问题