3

階層に属する複数の入力を持つ光沢のあるアプリがあります (A -> B -> C)。ユーザーが A を選択すると、B と C のオプションに影響するはずです。しかし、ユーザーは B しか選択できません (そして、他の入力にも影響するはずです。何も選択されていない場合は、すべてのオプションが利用できるはずです。どのように実装できますか?

4

2 に答える 2

3

より多くの情報が必要であり、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 })
  }
)

カスケード選択

于 2015-11-19T16:13:12.820 に答える