Frage

Ich weiß, dass ich mit dem folgenden Code ein normales Dropdown-Menü in Shiny erstellen kann,

selectInput("Input1", "Choose you Input:", choices = c('a1'='1','b2'='2'))

Dadurch wird das folgende Dropdown-Menü erstellt

enter image description here

Aber ich benutze bedingtesPanel und für die ich irgendwie bevölkere Inline-Dropdown-MenüDas ist so etwas

enter image description here

Ich verwende den folgenden Code, um diese Menüs zu generieren.

conditionalPanel(condition="input.conditionedPanels==3",
                     div(style="display:inline-block",
                         tags$label('Menu1', `for` = 'Sample'), 
                         tags$select(id = 'Sample', class="input-small")),
                     div(style="display:inline-block",
                         tags$label('Menu2', `for` = 'Sample1'), 
                         tags$select(id = 'Sample1', class="input-small")))

Mein Problem ist Ich kann diesem Dropdown-Menü keine Elemente hinzufügen.Ich habe Werte oder Optionen ausprobiert, aber das hat nichts geändert.

Ich hoffe, dass ich genügend Informationen bereitgestellt habe. Lassen Sie mich wissen, wenn weitere Informationen erforderlich sind.

War es hilfreich?

Lösung

Sie können eine Liste von Tags bereitstellen tagList.Die Tags, die Sie benötigen, sind option Tags mit value Attribute Sie können diese mit konstruieren mapply

library(shiny)

runApp(list(
  ui = bootstrapPage(
    numericInput('n', 'Enter 3 for condition', 3, 0, 10),
    conditionalPanel(condition="input.n==3",
                     div(style="display:inline-block",
                         tags$label('Menu1', `for` = 'Sample'), 
                         tags$select(id = 'Sample', class="input-small",
                                     tagList(mapply(tags$option, value = 1:10, 
                                                    paste0(letters[1:10], 1:10), 
                                                    SIMPLIFY=FALSE)))
                     ),
                     div(style="display:inline-block",
                         tags$label('Menu2', `for` = 'Sample1'), 
                         tags$select(id = 'Sample1', class="input-small",
                                     tagList(mapply(tags$option, value = 1:2, 
                                                    paste0(letters[1:2], 1:2), 
                                                    SIMPLIFY=FALSE)))
                     )
    )
    , textOutput("cond")
  ),
  server = function(input, output) {
    output$cond <- renderText({
      if(input$n == 3){
        paste0("Sample value selected =", input$Sample, " Sample1 value selected =",input$Sample1)
      }
    })
  }
))

Natürlich können Sie einfach verwenden selectInput im Inneren div Zum Beispiel:

library(shiny)

runApp(list(
  ui = bootstrapPage(
    numericInput('n', 'Enter 3 for condition', 3, 0, 10),
    conditionalPanel(condition="input.n==3",
                     div(style="display:inline-block",
                         selectInput("Sample", "Choose you Input:", choices = c('a1'='1','b2'='2'))
                     ),
                     div(style="display:inline-block",
                         tags$label('Menu2', `for` = 'Sample1'), 
                         tags$select(id = 'Sample1', class="input-small",
                                     tagList(mapply(tags$option, value = 1:2, 
                                                    paste0(letters[1:2], 1:2), 
                                                    SIMPLIFY=FALSE)))
                     )
    )
    , textOutput("cond")
  ),
  server = function(input, output) {
    output$cond <- renderText({
      if(input$n == 3){
        paste0("Sample value selected =", input$Sample, " Sample1 value selected =",input$Sample1)
      }
    })
  }
))
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top