我想实现一个复选框取消选择器模块,但是在尝试修改在模块UI外部定义的checkboxGroupInput对象时遇到了一个问题。
以下是说明我的问题的示例应用程序:
library(shiny) # Version 1.0.5
myModuleUI = function(id) {
ns = NS(id)
tagList(
actionButton(inputId = ns("reset_checkbox"), label = "Reset checkbox")
)
}
myModule = function(input, output, session) {
observeEvent(input$reset_slider, {
for(el in c("var1", "var2", "var3")){
updateCheckboxGroupInput(session,
inputId = el,
selected = "")
}
})
}
server <- function(input, output, session) {
callModule(myModule, id = "A")
}
ui <- fluidPage(
checkboxGroupInput("var1", "Variables to show:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear"),
selected = "cyl"),
checkboxGroupInput("var2", "Variables to show:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear"),
selected = "am"),
checkboxGroupInput("var3", "Variables to show:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear"),
selected = "gear"),
myModuleUI(id = "A")
)
shinyApp(ui = ui, server = server)