Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress bar and downloadHandler #1660

Closed
pata-eth opened this issue Apr 6, 2017 · 6 comments
Closed

Progress bar and downloadHandler #1660

pata-eth opened this issue Apr 6, 2017 · 6 comments

Comments

@pata-eth
Copy link

@pata-eth pata-eth commented Apr 6, 2017

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?

@jcheng5
Copy link
Member

@jcheng5 jcheng5 commented Apr 7, 2017

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.

@pata-eth
Copy link
Author

@pata-eth pata-eth commented Apr 7, 2017

Works like a charm. Thank you!

@pata-eth pata-eth closed this as completed Apr 7, 2017
@tbenschop
Copy link

@tbenschop tbenschop commented Aug 3, 2017

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

@ghost
Copy link

@ghost ghost commented Oct 13, 2017

@tbenschop What if you just have withProgress(message = 'This takes a minute or two',{ ?

@MohoWu
Copy link

@MohoWu MohoWu commented Dec 4, 2017

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?

@yaakovfeldman
Copy link

@yaakovfeldman yaakovfeldman commented Sep 16, 2018

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")).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants