I am having an weird issue when using conditional panels.
I have something similar to this
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")
))
))
If I remove either of the condition panels, the other renders when I select the correct option. However if I keep both conditional panels nothing shows, I don't get any error or message, it's like I am not sending any input. What gives?
The problem is that you have two outputs with the same id plot1
. If you change in this chunk outputId to plot3
conditionalPanel(
condition = "input.graphT == 'x'",
plotOutput(outputId = "plot1")),
and render the third plot on the server side it will work.
Example:
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)