Reputation: 77
I am fairly new to shiny and having a problem that I have seen others experience but I cannot seem to find a solution. My condtionalpanel in my Rshiny app is displaying all of my conditions. I have referenced the following links, even trying a renderUI solution, but had no luck. This seems like a simple issue I am just missing, but any help, an alternative solution to conditionalpanel, or insight on where the issue is would be much appreciated !
(The values in the boxes are then used to update a graph and when I use this solution in my app, the graphs are also no longer displaying. I am limited in how much other code I can share)
R shiny conditionalPanel displaying both conditions
To add the values in dynamically created textBox in RShiny
Producing dynamic/multiple input boxes to collect data depending on user selection in Shiny R
runApp(list(
ui = bootstrapPage(
selectInput("ctype","test:" , c("F", "S"), selected = F),
conditionalPanel("input.ctype == 'F'",
numericInput("comp", "Box 1", value = 100),
numericInput("comp1", "Box 2", value = 200),
numericInput("comp2", "Box3", value = 300),
actionButton("revert", "Back", icon = icon("history"))
),
conditionalPanel("input.ctype == 'S",
numericInput("comp3", "Box 4", value = 0))
),
server = function(input, output) {
output$plot <- renderPlot({ hist(runif(input$n)) })
}
))
Below is the current output. What I need is for when "F" is selected , only "Box 1", "Box 2", "Box 3" and "Back" appear and not "Box 4" . When "S" is selected only "Box 4" appears.
Upvotes: 1
Views: 334
Reputation: 11
You've got a missing closing apostrophe in the condition for your second conditionalPanel. If you add that back it will work as written.
Upvotes: 1
Reputation: 3152
I used renderUI option
runApp(list(
ui = bootstrapPage(
selectInput("ctype","test:" , c("F", "S"), selected = F),
uiOutput("comp")
),
server = function(input, output) {
output$comp <- renderUI({
if(input$ctype == "F"){
conditions <- list( fluidRow(
column(numericInput("comp", "Box 1", value = 100), width = 2),
column(numericInput("comp1", "Box 2", value = 200), width = 2),
column(numericInput("comp2", "Box3", value = 300), width = 2)),
actionButton("revert", "Back", icon = icon("history")))
}
if(input$ctype == "S") {
conditions <- numericInput("comp3", "Box 4", value = 0)
}
return(conditions)
})
output$plot <- renderPlot({ hist(runif(input$n)) })
}
))
Upvotes: 2