如何使用rmarkdown在pdf中呈现DT :: datatables? [英] how to render DT::datatables in a pdf using rmarkdown?
问题描述
如何从 rmarkdown
脚本中将 DT :: datatable
对象显示到pdf文档上?到目前为止,我的代码因以下错误而崩溃:
How can I display DT::datatable
objects from a rmarkdown
script onto a pdf document? My code so far is breaks down with the following error:
processing file: reportCopy.Rmd
output file: reportCopy.knit.md
Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML.
在YAML标头中包含 always_allow_html:是
抑制了该错误,但是pdf上没有任何内容。
Including always_allow_html: yes
in the YAML header suppresses the error, but nothing appears on the pdf.
我将不胜感激。我的代码当前为:
I would be grateful for any help. My code is currently:
---
title: "DT"
output: pdf_document
---
### Chart 1
```{r}
DT::datatable(head(mtcars))
```
(我不知道这是否重要,但实际上我的数据表是在<$ c中创建的$ c> shiny 应用程序。理想情况下,我希望将预渲染的表简单地转储到 rmarkdown
脚本中...但是我改变了策略现在尝试直接在 rmarkdown
代码中呈现表)
( I don't know if it matters, but my datatables are in fact created in a shiny
application. Ideally, I would have liked to have the prerendered tables simply dumped into the rmarkdown
script... but I switched tactic and now try to render the tables directly in the rmarkdown
code)
推荐答案
从knitr v1.13开始,HTML小部件将自动呈现为通过webshot软件包获取的屏幕截图。
Since knitr v1.13, HTML widgets will be rendered automatically as screenshots taken via the webshot package.
您需要安装webshot软件包和PhantomJS:
You need to install the webshot package and PhantomJS:
install.packages("webshot")
webshot::install_phantomjs()
(请参见 https: //bookdown.org/yihui/bo okdown / html-widgets.html )
这篇关于如何使用rmarkdown在pdf中呈现DT :: datatables?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!