繁体   English   中英

如何使用Knitr和Pandoc在Rmarkdown中包含DT数据表的js依赖关系

[英]Howto include js dependencies of DT datatable in Rmarkdown using knitr and pandoc

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

我正在尝试在RMarkdown文档中包括一个数据表小部件,然后我想使用knitr和pandoc将其转换为html。 这在RStudio上可以正常使用,但是如果我尝试对knitr和pandoc进行相同操作,则无法获得有效的html文件。

这是与RStudio一起使用的Rmd文件的最小示例,但不适用于其他示例:

--- 
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和datatables的js源。 我试图从软件包源中手动添加它们,但没有成功-并且无论如何都希望有一种开箱即用的解决方案。

RStudio使用的软件包是rmarkdown 它处理Knit命令,并将工作委托给knitr和pandoc,还负责捆绑依赖项并将其注入到文档中。

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

rmarkdown::render('example.Rmd')

更多资源:

CRAN上的RMarkdown

RMarkdown简介

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM