【发布时间】:2017-11-16 13:14:44
【问题描述】:
如何将rmarkdown 脚本中的DT::datatable 对象显示到pdf 文档上?到目前为止,我的代码因以下错误而崩溃:
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 上不会出现任何内容。
如果有任何帮助,我将不胜感激。我的代码目前是:
---
title: "DT"
output: pdf_document
---
### Chart 1
```{r}
DT::datatable(head(mtcars))
```
(我不知道这是否重要,但我的数据表实际上是在 shiny 应用程序中创建的。理想情况下,我希望将预渲染表简单地转储到 rmarkdown 脚本中......但是我改变了策略,现在尝试直接在rmarkdown 代码中呈现表格)
【问题讨论】:
-
如果你对谁在渲染表格很灵活,有 other table options 用于 R Markdown,比如
knitr::kable。 -
@AdamSpannbauer 感谢您的回答。我想我可能确实必须切换到 kable.. 但我宁愿不这样做,因为整个代码库(来自 Shiny 应用程序)是使用 DT::datatables 编写的。
-
你不能在
pdf_document中使用`datatable`(datatable是交互式的),只能在html_document中使用! PDF 的唯一可能性是使用kable或例如pandoc.table -
@Malvina_a 感谢您的评论....这是我最担心的。如果您确定,请不要犹豫,将其作为答案,我会接受。
标签: html r datatable r-markdown dt