Description
I would like to permit users to download a copy of a (quite) exact version of a shiny_prerendered
site. I.e., each user should be able to personalize its own version of a (dynamical) report, and save it in an HTML.
My main issue is the cache management of the data
chunk (which take few minutes to be computed).
I have tried to copy everything (caches included) in the static rendering folder, but {rmarkdown}
recreate a new data cache every time. The strange thing is that it recreates the cache even for multiple consecutive requests for the report. Moreover, this happens while the static rendering happens only, i.e. re-run the whole site correctly uses the cache (obviously :-))!
Step to reproduce
Within RStudio, create a project (eg rendercache/rendercache.Rproj
) with a folder inside named report/
and inside it the following test-cache.Rmd
file.
Then run it, and click the button to download the report. You can see that the caches in the folder report/test-cache_test/html
and the ones in report/static/test-cache_test/html
are different. Moreover, if you try to download a second time the report (within the same session!) the caches in the second folder (the static/
ones) changes again. The last thing has quite no sense to me, because the report should be reproduced in the exact the same way both the time!
---
params:
export: FALSE
runtime: shiny_prerendered
---
```{r setup, include=FALSE}
library(magrittr)
```
```{r data, include=FALSE, cache=TRUE}
my_bigdata <- mtcars
```
```{r download, eval=!params$export}
shiny::downloadLink("report", "Generate report")
```
```{r render, context="server", eval=!params$export}
output$report <- shiny::downloadHandler("test-cache.html",
function(file) {
static_dir <- "static"
dir <- fs::dir_create(static_dir)
list.files(all.files = TRUE, include.dirs = TRUE) %>%
setdiff(c(".", "..", static_dir)) %>%
file.copy(dir, recursive = TRUE, copy.date = TRUE)
report <- fs::path(dir, "test-cache.Rmd")
rmarkdown::render(report, "html_document", file,
params = list(export = TRUE),
runtime = "static",
envir = new.env(parent = globalenv())
)
}
)
```
References
Shiny pre-rendered documents and context chunks.
Download reactive objects (but I do not need this).
externalize rendering from download (does not change this issue)
Main question
Is there a way to re-render a (possibly modified) whole copy of a Shiny pre-rendered
.Rmd
maintaining/reusing its data-cache while using a "static" runtime?