2017-01-30 56 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