Search code examples
rshinyr-markdownshiny-server

rmarkdown::render() doesn't allow multiple users at the same time?


I have a shiny app that renders an HTML report from an action button. Once this is rendered, a download button shows up in the screen so that the result of that action button can be downloaded. I had to create this two separate buttons because the download handler seems to have a time out, so since my Rmd file takes a bit longer to render, it wouldn't work and it throws an error in the server.

I am currently rendering my Rmd like in the following:

rmarkdown::render(tempReport, output_file = tmp_file,
                              params = params,
                              envir = new.env(parent = globalenv()))

The problem is: if one user is rendering his/her report in the server, if a second user clicks the action button to render it at the same time, it will only start rendering once the first user is finished.

Does anyone have any solutions to this?


Solution

  • The behavior you are observing is a result of the fact that R is single-threaded. The direct answer to your issue is that you need to implement asynchronous methods to allow multiple render() processes to run concurrently. More on this at: https://rstudio.github.io/promises/.

    If you don't want to go down the asynchronous path and there are a reasonable number of possible report variants, you can pre-render the output and have the user simply open the selected output rather than rendering on-demand.