R Shiny如何构建动态的conditionalPanel

时间:2017-01-30 13:29:28

标签: r shiny

实施例

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()输入的例子?

我想知道如何在conditionalPanel()中使用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

我想在a,b,c和d之间做出选择,之后我想在a1,a2,a3之间做出选择,如果我选择a,b1和b2,如果我选择b,ecc。

我可以手工完成,但我有很多变量和动态子分布。

谢谢

1 个答案:

答案 0 :(得分: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"
    )
})