1

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. enter image description here

CJJ
  • 75
  • 9

2 Answers2

2

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


Johan Rosa
  • 2,797
  • 10
  • 18
  • Thank you so much @johan !! This is exactly what I was looking for !.....As a follow up, if I wanted to plot the boxes, next to each other, rather than stacked, would that be done in the server or the ui (I don't have too much background in renderUI objects)? – CJJ May 02 '19 at 02:28
  • using the function `column()` in each box, inside a `fluidRow`. All this in the `server`. I'm editing the anwer for you. – Johan Rosa May 02 '19 at 13:29
1

You've got a missing closing apostrophe in the condition for your second conditionalPanel. If you add that back it will work as written.

  • Welcome to SO! Elaborate a bit more on your answer - e.g., include a line of correct code in your answer. Otherwise this might be deleted by some older folks here who check for short and low-quality answers. – tjebo Jul 23 '19 at 15:13