Hello folks, I am using downloadHandler to render an Rmarkdown file in PDF format. The process takes a while so I wanted to include a progress bar to let the user know that the file is being generated. I was not able to figure out how to do so.
The progress bar is generated by:
progress <- Progress$new(session, min = 1, max = 2)
progress$set(message = "Generating Report... ", value = 1)
on.exit(progress$close())
downloadHandler is not designed to work within an 'observe' block so I do not really know how to make these two features play together.
Any idea how I can achieve what I need?
You should be able to use the Progress API (or the simpler withProgress) from within the downloadHandler's content function. LMK if you need more explanation than that, or if it's not working as expected.
Works like a charm. Thank you!
I tried to include it in the content function:
output$Download_Selected_Snapshot<-downloadHandler(
filename = function() {
paste0('Inputfile_',unique(New_Data()$DT_latest$PoolCutoffDate),'.xlsx')
},
content = function(file) {
withProgress('Exporting..',value = 0,message = 'This takes a minute or two',{
wb <- createWorkbook()
addWorksheet(wb = wb, sheetName = "Sheet 1", gridLines = FALSE)
writeDataTable(wb = wb, sheet = 1, x =getrawdata())
})
saveWorkbook(wb, file, overwrite = TRUE)
}
)
But this is not working, I guess I'm doing it not in the correct way? Thanks, Tim
@tbenschop What if you just have withProgress(message = 'This takes a minute or two',{ ?
I have tried wrapping the withProgress around the render function. It does show a progress bar in the UI, but it just gets stuck at 10%, which is the default value. How I can make the withProgress know the actual progress of the rendering process and adjust the progress bar accordingly?
For all those people adding thumbs up to the question by @MohoWu , you can update a progress bar from render by doing the render in the existing environment that the shiny app is running in (instead of specifying a new environment), then updating the progress bar from your markdown document itself.
If you want to be able to call the same Rmd file from shiny and static contexts, you can wrap the calls to inc in the Rmd file with a test to see if the file is being rendered from a shiny context, such as if (identical(rmarkdown::metadata$runtime, "shiny")).
Most helpful comment
I have tried wrapping the
withProgressaround therenderfunction. It does show a progress bar in the UI, but it just gets stuck at 10%, which is the default value. How I can make thewithProgressknow the actual progress of the rendering process and adjust the progress bar accordingly?