R - Markdown:在 html 报告中打印 View() 的结果

R - Markdown : Printing the result of View() in a html report

有没有一种方法可以在 html Rmarkdown 报告中打印 View() 函数的结果,而无需截取它的屏幕截图,然后将其作为 .png 图片添加到文件中?

非常感谢!

我可以建议设置 DT 包吗?

---
title: "test"
output: html_document
---
```{r setup}
DT::datatable(mtcars, class = 'cell-border stripe', options = list(pageLength = nrow(mtcars)))
```

仅用 1 行 Rmarkdown 代码,我们就得到了我认为非常接近 View() 输出的结果。 DT 包非常易于使用,将使您的 HTML 报告看起来非常专业,具有每页行数、可下载表格、搜索能力和数据透视表能力的选项