9

I've noticed that when I have an Rmd with runtime: shiny in the YAML, code chunks don't seem to be read from cache. I'm wondering if using the shiny engine for rmarkdown just doesn't support chunk caching, or am I doing something wrong?

Example Rmd file:

---
title: "Cache test"
output: html_document
---

```{r cache=TRUE}
Sys.sleep(10)
```

If you run this 5 times, only the first time will take 10 seconds, and any subsequent run will be fast.

But if you add the runtime: shiny option to the YAML, then every single run will take 10 seconds.

(PS question: any better way to test whether or not code chunks cache is being used?)

1 Answer 1

2

i ran into the same problem where, in runtime: shiny, the cache switch was ignored.

Nowadays there is a workaround, using runtime: shiny_prerendered and context="data" with cache=TRUE:

---
title: "Cache test"
output: html_document
runtime: shiny_prerendered
---

```{r,context="data", cache=TRUE}
Sys.sleep(10)
```

this behaves as expected; on the first run, rendering takes 10 seconds; on all subsequent runs, the cached chunk is used.

2
  • 2
    Yes, this shiny prerendered is a great addition by rstudio :)
    – DeanAttali
    Commented May 22, 2017 at 15:42
  • @DeanAttali If it works, don't forget to accept the answer.
    – Yihui Xie
    Commented Sep 1, 2017 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.