如何在R中将flextable另存为png
我已经遵循了链接的建议:,但似乎我面临着一个不同的问题,因为这个解决方案对我不起作用。vanilla.table函数生成flextable函数以外的对象 我使用flextable是因为它允许理想的格式设置 例如:如何在R中将flextable另存为png,r,png,viewer,flextable,R,Png,Viewer,Flextable,我已经遵循了链接的建议:,但似乎我面临着一个不同的问题,因为这个解决方案对我不起作用。vanilla.table函数生成flextable函数以外的对象 我使用flextable是因为它允许理想的格式设置 例如: library(flextable) library(rtable) # The example below work. myft <- vanilla.table( head(mtcars) ) myft writeLines(as.html(myft), "MyFle
library(flextable)
library(rtable)
# The example below work.
myft <- vanilla.table(
head(mtcars) )
myft
writeLines(as.html(myft), "MyFlexTable.html")
# The example below does not work.
myft <- regulartable(
head(mtcars),
col_keys = c("am", "carb", "gear", "mpg", "drat" ))
myft
writeLines(as.html(myft), "MyFlexTable.html")
ps:我知道可以通过单击导出>另存为图像手动下载照片,但我需要对其进行编程
提前谢谢 要将flextable保存为png,首先需要将其保存为html文件,然后使用webshot从html文件中获取png
library(flextable)
myft <- regulartable(
head(mtcars),
col_keys = c("am", "carb", "gear", "mpg", "drat" ))
# create an Rmd file ----
library(rmarkdown)
rmd_name <- tempfile(fileext = ".Rmd")
cat("```{r echo=FALSE}\nmyft\n```", file = rmd_name)
# render as an html file ----
html_name <- tempfile(fileext = ".html")
render(rmd_name, output_format = "html_document", output_file = html_name )
# get a png from the html file with webshot ----
library(webshot)
webshot(html_name, zoom = 2, file = "regulartable.png",
selector = "body > div.container-fluid.main-container > div.tabwid > table")
直到最近,当文本以粗体显示时,该方法无法捕获时,该方法才发挥了完美的作用。使用MacOS 10.14.4、webshot 0.5.1和R 3.5.0。如果遇到错误,请使用flextable::将_另存为_图像并在GH页面中打开问题: