如何使用 rmarkdown 在 pdf 中呈现 DT::datatables? [英] how to render DT::datatables in a pdf using rmarkdown?

查看:34
本文介绍了如何使用 rmarkdown 在 pdf 中呈现 DT::datatables?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 DT::datatable 对象从 rmarkdown 脚本显示到 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: yes 会抑制错误,但 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))
```

(我不知道这是否重要,但我的数据表实际上是在 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/bookdown/html-widgets.html)

这篇关于如何使用 rmarkdown 在 pdf 中呈现 DT::datatables?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆