[英]how to save flextable as png in R
我已經按照鏈接的建議進行操作: R將FlexTable保存為script中的html文件 ,但是似乎我遇到了一個不同的問題,因為此解決方案不適用於我。 vanilla.table ()
函數生成除flextable ()
函數之外的對象。
我正在使用flextable
因為它允許理想的格式化可能性
例:
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")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.