Validate inside downloadHandler
I want to perform some validation inside downloadHandler, so that when the condition is true a custom message is given else download of data. I have the following code example where I want to perform validation, but it seems not working.
shinyApp(
ui = basicPage(
textInput("jobid", label = "Enter job ID", value = ""),
downloadLink("downloadData", "Download")
),
server <- function(input, output) {
# Our dataset
data <- mtcars
output$downloadData <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
if(input$jobid ==""){
session$sendCustomMessage(type = 'testmessage',
message = 'No job id to submit')
}else
write.csv(data, file)
}
)
}
)
How to validate??