2017-01-30 81 views
1

例子[R閃亮如何建立一個動態conditionalPanel

sidebarPanel(
    selectInput(
     "plotType", "Plot Type", 
     c(Scatter = "scatter", 
     Histogram = "hist")), 

    # Only show this panel if the plot type is a histogram 
    conditionalPanel(
     condition = "input.plotType == 'hist'", 
     selectInput(
     "breaks", "Breaks", 
     c("Sturges", 
      "Scott", 
      "Freedman-Diaconis", 
      "[Custom]" = "custom")), 

     # Only show this panel if Custom is selected 
     conditionalPanel(
     condition = "input.breaks == 'custom'", 
     sliderInput("breakCount", "Break Count", min=1, max=1000, value=10) 
    ) 
    ) 
) 

大家好。這是conditionalPanel()輸入的例子嗎?

我想知道如何使用conditionPanel()內的selectInput的輸出。

例如,我要一個這樣的程序:

condition = "input.plotType == 'input$plotType'", 
     selectInput(-- here -- depends on the input) 

我的輸入是這樣的:

a a1 
a a2 
a a3 
b b1 
b b2 
c c1 
c c2 
d d1 
d d2 
d d3 

我想一個,b,c和d之間後,我會選擇喜歡在a1,a2,a3之間進行選擇,如果我選擇b,ecc,則選擇a,b1和b2。

我可以用手工做,但我有很多變量和一個動態子分佈。

謝謝

回答

1

看看renderUI()。

UI端:

conditionalPanel(
     condition = "input.plotType == 'hist'", 
     uiOutput("fromServer") 
), 

服務器端:

output$fromServer <- renderUI({ 
    ## Now you can use inputs like input$plotType to build your selectInput 
    selectInput(
     "breaks", "Breaks", 
     c("Sturges", 
      "Scott", 
      "Freedman-Diaconis", 
      "[Custom]" = "custom" 
    ) 
}) 
+0

泰。我使用renderUI解決了這個問題。 – miciobauciao