Hello everyone,
I am trying to create a downloadButton() in UI and downloadHandler() in server. The goal is to prevent the download if certain conditions are not met, for example if the selectInput() is blank or no option selected. As an example here is the code:
library(shiny)
ui <- fluidPage(
selectInput(inputId="select",
label="Choose variable:",
choices=c("","rock","car","pressure"),
selected = NULL),
br(),
downloadButton("downloadData", "Download")
)
server <- function(input, output) {
data <- mtcars
output$downloadData <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
write.csv(data, file)
}
)
}
shinyApp(ui, server)
I want to make the downloadButton only works if (input$select != ""), otherwise it should give like a pop-up message or an error like mentioned in Message popup. I have tried different things with if else() options but it did not work. Could anybody help me?