ConditionalPannels没有显示

时间:2016-05-09 11:01:16

标签: r shiny shiny-server

使用条件面板时,我遇到了一个奇怪的问题。

我有类似的东西

shinyUI(bootstrapPage(


selectInput(inputId = "graphT",
              label = "Type of Graph :",
              choices = c("x","y"),
              selected =  "x"),


conditionalPanel(
      condition = "input.graphT == 'x'",
      plotOutput(outputId = "plot1")),

conditionalPanel(
      condition = "input.graphT == 'y'",
      splitLayout(
      cellWidths = c("50%", "50%"),
        plotOutput(outputId = "plot1"),
        plotOutput(outputId = "plot2")
       ))

))

如果我删除了其中一个条件面板,则当我选择正确的选项时,另一个会呈现。但是,如果我保留两个条件面板没有任何显示,我不会收到任何错误或消息,它就像我没有发送任何输入。是什么给了什么?

1 个答案:

答案 0 :(得分:1)

问题是您有两个具有相同ID plot1的输出。如果您将此块输出更改为plot3

conditionalPanel(
      condition = "input.graphT == 'x'",
      plotOutput(outputId = "plot1")),

并在服务器端渲染第三个图,它将起作用。

示例:

library(shiny)
ui <- shinyUI(bootstrapPage(


  selectInput(inputId = "graphT",
              label = "Type of Graph :",
              choices = c("x","y"),
              selected =  "x"),


  conditionalPanel(
    condition = "input.graphT == 'x'",
    plotOutput(outputId = "plot3")),

  conditionalPanel(
    condition = "input.graphT == 'y'",
    splitLayout(
      cellWidths = c("50%", "50%"),
      plotOutput(outputId = "plot1"),
      plotOutput(outputId = "plot2")
    ))

))

server <- function(input, output) {
 output$plot1 <- renderPlot({
   plot(1)
 }) 

 output$plot2 <- renderPlot({
   plot(1:10)
 }) 

 output$plot3 <- renderPlot({
   plot(1:100)
 })
}

shinyApp(ui, server)