Ted
Ted

Reputation: 105

conditionalPanel Display but condition is not met - R Shiny

I have just started to do up the UI using Shiny with R, however I am having some problem with the layout of my page.

The problem I am facing is my second conditionalPanel is showing even though it is not selected. I put the selected='Item1' in my radioButtons, however the checkboxGroupInput of Item2 is showing as well.

What is the problem here and how do I go around fixing it? Is there any error or mistake in my code?

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") 
                         ) 
                     )
         )))

Upvotes: 2

Views: 967

Answers (1)

Ted
Ted

Reputation: 105

I have found the solution to this problem. Thank a lot Wannes Rosiers, where I have found and troubleshoot this error.

For both the mainPanel at tabPanel subtitle1 and subtitle2, Both of it were having the same plotOutput, which is "plot",

mainPanel(
 plotOutput("plot")   
 )

Both of them should have different output, though I am not sure the reason behind it.

Upvotes: 3

Related Questions