I am trying to display a panel in shiny only when both files are uploaded.
shinyApp(
ui = fluidPage(
fileInput('fileInput_pd', 'Add the file'),
fileInput('fileInput_di', 'Add the file'),
conditionalPanel(
condition = "(input.fileInput_pd && input.fileInput_di) is true",
selectInput("smoothMethod", "Method",
list("lm", "glm", "gam", "loess", "rlm"))
),
downloadButton('report', 'Generate report')
),
server = function(input, output) {
observe({
if(is.null(input$fileInput_pd) | is.null(input$fileInput_di)) {
return()
} else {
var_example <- 2
}
}
)
}
)
With the code as above, it generates the conditionalPanel at the start. Any sugestions of what can I do?
Rather than trying to read in input directly, you can create a reactive variable on the output that indicates when the data is ready to be used. For example
library(shiny)
shinyApp(
ui = fluidPage(
fileInput('fileInput_pd', 'Add the file'),
fileInput('fileInput_di', 'Add the file'),
conditionalPanel(
condition = "output.filesUploaded",
selectInput("smoothMethod", "Method",
list("lm", "glm", "gam", "loess", "rlm"))
),
downloadButton('report', 'Generate report')
),
server = function(input, output) {
observe({
if(is.null(input$fileInput_pd) | is.null(input$fileInput_di)) {
return()
} else {
var_example <- 2
}
}
)
output$filesUploaded <- reactive({
val <- !(is.null(input$fileInput_pd) | is.null(input$fileInput_di))
print(val)
})
outputOptions(output, 'filesUploaded', suspendWhenHidden=FALSE)
}
)
This was basically just sightly adapted from this answer and changed to it checks two files instead of one,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With