rmarkdown::render() 不允许同时有多个用户?

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

我有一个闪亮的应用程序,可以通过操作按钮呈现 HTML 报告。渲染完成后,屏幕上会显示一个下载按钮,以便可以下载该操作按钮的结果。我必须创建这两个单独的按钮,因为下载处理程序似乎超时,所以由于我的 Rmd 文件需要更长的时间来呈现,它不会工作并且会在服务器中引发错误。

我目前正在渲染我的 Rmd,如下所示:

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.

有人对此有任何解决方案吗?

您观察到的行为是 R 是单线程的结果。您的问题的直接答案是您需要实现异步方法以允许多个 render() 进程同时 运行。有关更多信息,请访问:https://rstudio.github.io/promises/.

如果您不想走异步路径并且有合理数量的可能报表变体,您可以预呈现输出并让用户只需打开选定的输出而不是按需呈现.