1

I am trying to a multi tab app, I want the the second tab's page layout to be conditional on an input from the first panel. Basically if the value in the first panel is 1 I want the second panel to display 1 set of file inputs if the user puts in the value 2 in the first panel then I want the second panel to display 2 file inputs. Currently my code displays both conditions, and I am unsure why. See the reproducible code below.

ui = 
navbarPage("Page Title",
  tabPanel("Panel 1",
    sidebarPanel(
        ## Add Name,
        ## Number of surveys analysising
        numericInput("n_values", "Number of columns in next panel:", 1, min = 1, max = 2)
    ),
    mainPanel(
      tags$div(
        h2("Home Page") 
      )
    )
   ),
    tabPanel("Panel 2",
      conditionalPanel(condition = "input.n_values == 1",
        fixedPage(theme = "flatly",
          fixedRow(
            column(2,"First Column",
              fileInput("File1", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F),
              p("Click the button to check the data was read in correctly")
            ),
            fixedRow(
              column(12,
                verbatimTextOutput("errorText")
              )
            )    
          )
        )
      ),
      conditionalPanel(condition = "input.n_values == 2",
        fixedPage(theme = "flatly",
          fixedRow(
            column(2,"First Column",
              fileInput("File1", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F),
              p("Click the button to check the data was read in correctly")
            ),
            column(2,"Second Column",
              fileInput("File2", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F),
              p("Click the button to check the data was read in correctly")
            ),          
            fixedRow(
              column(12,
                verbatimTextOutput("errorText")
              )
            )    
          )
        )
      )      
    )  
  )

server = function(input, output,session) {
  ## Call the error message function and print
  output$errorText <- renderText({
    validate(
      need(!is.null(input$File1)
             , 'You need to input the files before we can validate the data. Please select all the necessary files.')
      )
  })
} 

shinyApp(ui, server)
Cyrillm_44
  • 701
  • 3
  • 17

1 Answers1

2

That's because you have verbatimTextOutput("errorText") twice in your UI. You can't do that in Shiny. An output must be included at one place only.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • Thanks for that, How can I have parts of the page conditional and parts of the page common among conditions. I would like each condition to have a text box below the conditional file inputs? – Cyrillm_44 Dec 10 '17 at 20:44
  • 1
    @Cyrillm_44 You could simply define the text in a `reactive` element and make two identical `output$errorText1` and `output$errorText2` rendering the value of the `reactive` element. – Stéphane Laurent Dec 10 '17 at 20:58