【问题标题】:Possible to use knitr cache chunk in interactive rmarkdown doc?可以在交互式 rmarkdown 文档中使用 knitr 缓存块吗?
【发布时间】:2015-07-26 14:47:33
【问题描述】:

我注意到,当我在 YAML 中有一个带有 runtime: shiny 的 Rmd 时,似乎没有从缓存中读取代码块。我想知道是否使用闪亮引擎进行 rmarkdown 只是不支持块缓存,还是我做错了什么?

示例 Rmd 文件:

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

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

如果你运行 5 次,只有第一次需要 10 秒,随后的任何运行都会很快。

但如果你在 YAML 中添加 runtime: shiny 选项,那么每次运行都需要 10 秒。

(PS 问题:有什么更好的方法来测试是否使用了代码块缓存?)

【问题讨论】:

    标签: r shiny knitr r-markdown shiny-server


    【解决方案1】:

    我遇到了同样的问题,在 runtime: shiny 中,cache 开关被忽略了。

    现在有一种解决方法,将runtime: shiny_prerenderedcontext="data"cache=TRUE 一起使用:

    ---
    title: "Cache test"
    output: html_document
    runtime: shiny_prerendered
    ---
    
    ```{r,context="data", cache=TRUE}
    Sys.sleep(10)
    ```
    

    这符合预期;第一次运行,渲染需要 10 秒;在所有后续运行中,都会使用缓存的块。

    【讨论】:

    • 是的,这个闪亮的预渲染是 rstudio 的一个很好的补充 :)
    • @DeanAttali 如果有效,请不要忘记接受答案。
    猜你喜欢
    • 2017-09-16
    • 2017-09-17
    • 2014-09-05
    • 2015-09-20
    • 2022-12-01
    • 1970-01-01
    • 2018-03-24
    • 2012-09-26
    • 2015-02-16
    相关资源
    最近更新 更多