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