The data in my shiny application takes a few seconds to be processed. I have a download button and I would like it to be either unclickable until the data are prepared or have the download handler wait until prepared. At the moment clicking the download button before 5 secs returns the default html file and then after 5 secs it behaves as expected.
My current solution is to use `shinyjs::hide/show. I’ve shown this below.
Is this best practice? Also, why the shinyjs::useShiny()
at the start? It seems unique to that package.
ui <- fluidPage(
shinyjs::useShiny(),
shinyjs::hidden(downloadButton("downloadData", "Download"))
)
server <- function(input, output) {
# Our dataset
data <- mtcars
if(is.null(mtcars)){shinyjs::hide(“downloadData”)}
else{shinyjs::show(“downloadData”)}
output$downloadData <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
write.csv(data, file)}
)
}
shinyApp(ui, server)