conditionalPanel显示但不满足条件 - R Shiny

时间:2015-08-17 03:02:23

标签: r shiny

我刚刚开始使用Shiny with R来完成UI,但是我的页面布局有问题。

我面临的问题是我的第二个conditionalPanel正在显示,即使它未被选中。我把选中的=' Item1'在我的radioButtons中,但是也显示了Item2的checkboxGroupInput。

这里有什么问题,如何解决这个问题?我的代码中是否有错误或错误?

library("shiny")

shinyUI(navbarPage("title",
tabPanel("Subtitle1",
 sidebarLayout(
  sidebarPanel(
      checkboxGroupInput("variable1","Items:",
                         c("Item1","Item2"))),
  mainPanel(
   plotOutput("plot")   
   )
  )
 ),

tabPanel("Subtitle2",
         sidebarLayout(
             sidebarPanel(
                 radioButtons(
                     inputId="Item",
                     label="Item Selection:",
                     choices=list(
                         "Item1","Item2"),
                     selected='Item1'
                             ),
# Only show this when Item1 is selected. Become invisible when other Items is selected.
                 conditionalPanel(
                     condition="input.Item == 'Item1'",
                     checkboxGroupInput(
                         "variable2",
                         "Countries:",
                         choices=names(QuantityI),
                         selected= "World.")
                                 ),
# Only show this when Item2 is selected. Become invisible when other Items is selected.
                 conditionalPanel(
                     condition="input.Item == 'Item2'",
                     checkboxGroupInput(
                         "variable2",
                         "Countries:",
                         choices=names(QuantityI),
                         selected= "World.")
                                 )
                        ),
            mainPanel(
                     plotOutput("plot") 
                         ) 
                     )
         )))

1 个答案:

答案 0 :(得分:3)

我找到了解决这个问题的方法。非常感谢Wannes Rosiers,我找到并解决了这个错误。

对于tabPanel字幕1和副标题2的mainPanel, 它们都具有相同的plotOutput,即“plot”,

mainPanel(
 plotOutput("plot")   
 )

它们都应该有不同的输出,但我不确定背后的原因。