0

I am facing an issue with conditionalPanel in a ShinyApp. My problem can be stated as follows: I want to display a given message if demo data have been selected (or not) and if data have been uploaded (or not). The part for the demo data is working; but not the one for the uploaded data (something should be wrong with the condition input.allDomainFiles == [...]. I have tried several conditions (== false, == '', ...) but nothing worked so far...

Here is my code so far (minimal example):

library(shiny)

ui <- fluidPage(
  sidebarLayout(  
    sidebarPanel(
  checkboxInput('demo', 'Example with demo data', TRUE),
  conditionalPanel(
    condition="input.demo == false",
    tags$hr(),
    fileInput("allDomainFiles",
              label=("Files with coordinates"), multiple=TRUE, placeholder="--- load your files ---"),
    tags$hr()
  )
    ),
  mainPanel(
    tabsetPanel(
      tabPanel("Loaded data",
               conditionalPanel(condition="input.demo == true",
                                tags$span(style="color:green",tags$div("Selected demo data",id="nodata1")),
               ),
               conditionalPanel(condition="input.demo == false",
                                tags$span(style="color:orange",tags$div("Not demo data",id="nodata2")),
               ),
               conditionalPanel(condition="input.allDomainFiles == '' ",
                                tags$span(style="color:orange",tags$div("No loaded data",id="nodata3")),
               ),
               conditionalPanel(condition="input.allDomainFiles != '' ",
                                tags$span(style="color:green",tags$div("Loaded data",id="nodata4")),
               ),
               verbatimTextOutput("results") # just for debug
  )))))

server <- shinyServer(function(input, output) {
  output$results <- renderPrint({
    print(input$allDomainFiles)
    input$allDomainFiles
  })
})

shinyApp(ui, server)

I have also tried a "reactive version" (as previously suggested here) by adding in the server part

getData <- reactive({
  if(is.null(input$allDomainFiles)) return(NULL)
  return(1)
})
output$fileUploaded <- reactive({
  return(!is.null(getData()))
})

and testing in the ui part

if(ouptut.fileUploaded == true)

but it also did not work (btw, the demo part seems to work without being explicitly reactive...)

Could someone help and make this minimal example working ?

Thanks a lot in advance...

PS-disclaim: I am a total newbie in R/Shiny, so please be indulgent ;)

Erica Fary
  • 363
  • 1
  • 2
  • 10
  • 1
    The [answer you have linked](https://stackoverflow.com/a/21535587/1100107) shows the way to go. But you have not strictly followed it. You need `outputOptions(......)` and the condition `"output.fileUploaded == true"` in the conditional panel. – Stéphane Laurent Mar 01 '21 at 09:51
  • aah you are right, I did not correctly set the `outputOptionsline`... oups ^^... thanks !!! But now could you (or anyone else) explain why for the demo it does not need to be handled with `reactive` function(s) in the server part ? – Erica Fary Mar 01 '21 at 13:00

0 Answers0