【问题标题】:Howto include js dependencies of DT datatable in Rmarkdown using knitr and pandoc如何使用 knitr 和 pandoc 在 Rmarkdown 中包含 DT 数据表的 js 依赖项
【发布时间】:2015-04-02 22:32:06
【问题描述】:

有没有办法用 RStudio 之外的 DT 生成的数据表来编译 RMarkdown 文档?

我正在尝试在 RMarkdown 文档中包含一个数据表小部件,然后我想使用 knitr 和 pandoc 将其转换为 html。这适用于 RStudio,但如果我尝试对 knitr 和 pandoc 做同样的事情,我将无法获得工作的 html 文件。

下面是一个 Rmd 文件的最小示例,该文件可与 RStudio 一起使用,但不能与 RStudio 一起使用:

--- 
title: "Minimal DT example"
---

<style type="text/css"> table, table th, table td {   border: none; } </style>

```{r} 
library(DT) 
datatable(iris) 
```

然后我想使用以下方法将其转换为 html:

knitr::knit('example.Rmd')
knitr::pandoc('example.md',format="html")

我知道 RStudio 使用了更复杂的 pandoc 调用:

/usr/lib/rstudio/bin/pandoc/pandoc scratch.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output scratch.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template /home/user/R/x86_64-pc-linux-gnu-library/3.1/rmarkdown/rmd/h/default.html --variable 'theme:bootstrap' --include-in-header /tmp/RtmpMLtVfF/rmarkdown-str24935297671d.html --mathjax --variable 'mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --no-highlight --variable highlightjs=/home/user/R/x86_64-pc-linux-gnu-library/3.1/rmarkdown/rmd/h/highlight

我可以重新创建此 tmp 文件包含在标头中的部分:

/tmp/RtmpMLtVfF/rmarkdown-str24935297671d.html

我假设这个文件包含 jquery 和数据表的 js 源。我试图从包源中手动添加它们 - 但没有成功 - 并且无论如何都希望有一个开箱即用的解决方案。

【问题讨论】:

    标签: r datatable rstudio r-markdown


    【解决方案1】:

    RStudio 在后台使用的包是rmarkdown。它处理 Knit 命令并将工作委托给 knitr 和 pandoc,它还负责捆绑依赖项并将它们注入到 doc 中。

    您可能已经安装了该软件包,因此您应该能够一次性生成您的 HTML 文件:

    rmarkdown::render('example.Rmd')
    

    更多资源:

    RMarkdown on CRAN

    RMarkdown Introduction

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-30
      • 2013-10-03
      • 2014-04-04
      • 2017-10-31
      • 2019-02-05
      • 2019-02-26
      • 2021-11-30
      • 2017-10-13
      相关资源
      最近更新 更多