[英]Shiny, observeEvent, updateSelectInput, inputs resetting
[英]Shiny updateSelectInput for multiple inputs
我有闪亮的应用程序,其中包含多个属于层次结构的输入(A-> B-> C)。 当用户选择A时-它会影响B和C中的选项。但是,用户只能选择B(然后它也会影响其他输入。如果未选择任何内容-所有选项都应该可用。如何实现它?
同意您需要更多信息,并且observe
模式可能很合适。 如果需要在界面中进行更多控制和动态处理,则可以将动态UI与renderUI
:
library(shiny)
choices_A <- list("Choice A" = 1, "Choice B" = 2, "Choice C" = 3)
choices_B <- list("Choice B1" = 4, "Choice B2" = 5, "Choice B3" = 6)
choices_C <- list("Choice C1" = 7, "Choice C2" = 8, "Choice C3" = 9)
shinyApp(
ui = fluidPage(
titlePanel("Cascading selects"),
fluidRow(
column(3, wellPanel(
selectInput("select_A", label = "Select A",
choices = choices_A)
)),
column(3, wellPanel(
uiOutput("ui")
)),
column(3, wellPanel(
tags$p("First Input: "),
verbatimTextOutput("value"),
tags$p("Dynamic Input: "),
verbatimTextOutput("dynamic_value")
))
)
),
server = function(input, output) {
output$ui <- renderUI({
if (is.null(input$select_A))
return()
switch(input$select_A,
"1" = selectInput("dynamic", label = "Select A2",
choices = choices_A),
"2" = selectInput("dynamic", label = "Select B",
choices = choices_B),
"3" = selectInput("dynamic", label = "Select C",
choices = choices_C)
)
})
output$value <- renderPrint({ input$select_A })
output$dynamic_value <- renderPrint({ input$dynamic })
}
)
这里没有足够的信息。 但是,根据您的描述,您可以尝试从这里开始。
shinyServer(function(input, output, session) {
observe({
a_option <- input$a_option
b_option <- input$b_option
if (a_option == "XXX") {
updateSelectInput(session, "B", choices = b_options)
updateSelectInput(session, "C", choices = c_options)
}
if (b_option == "XXX") {
updateOtherInput(session, "input_id", ...)
}
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.