谢谢@易慧,
我想通了这个问题。基本上,解决方案是按webshot
功能截取屏幕截图knitr::include_graphics
并将此 png 文件插入到 pdf 输出中。
请在您的降价中尝试这段代码:
```{r TableJiena, out.width = "700px", out.length = "400px"}
insert_screenshot = function(x) {
if (!inherits(x, c('html', 'shiny.tag'))) return()
htmltools::save_html(x, 'temp.html')
res = webshot::webshot('temp.html', 'my-screenshot.png')
knitr::include_graphics(res)
}
insert_screenshot(htmltools::HTML(as.html(vanilla.table(head(iris)))))
```
如果您想获得简化的代码,请在 Markdown 中尝试这段代码。
```{r TableJiena, out.width = "700px", out.length = "400px"}
webshot::webshot(htmltools::HTML(as.html(vanilla.table(head(iris)))), 'my-screenshot.png')
knitr::include_graphics('my-screenshot.png')
```
但是这个解决方案有个小问题:PNG图片的解决方案不是很高,不知道为什么每列之间有流量。此外,一些单行打印成双行。
谁能弄清楚如何解决这个小问题webshot
?
谢谢!