我使用"可识别"的pkg/函数在R中创建了一个漂亮的表格。我可以将其导出(实际上,编织(为 HTML 页面,但是有没有办法将其导出为图像(如果是这样,则自动(? 不是必需的,但这里有一些代码:
x<-as.data.frame(list(a=c("why","can't","I","figure","this","out"),b=c("it","is","probably","something","really","simple")))
reactable(x)
我没有尝试过,但这应该有效。reactable
生成一个htmlwidget
。因此,您可以使用htmlwidgets
包的saveWidget
功能将表保存在html文件中,然后使用webshot
包拍摄快照。
library(reactable)
library(htmlwidgets)
library(webshot)
rtable <- reactable(iris[1:8,])
html <- "rtable.html"
saveWidget(rtable, html)
webshot(html, "rtableSnapshot.png") # you can also export to pdf
下面是使用saveWidget
将 Reactable 表另存为 HTML 文件的示例,然后使用该文件和webshot2
创建.png。这有帮助吗?
library("reactable")
library("htmlwidgets")
library("webshot2")
html_file <- "table.html"
img_file <- "img.png"
df <- mtcars[1:3, 1:3]
table <- reactable(df)
saveWidget(widget = table, file = html_file, selfcontained = TRUE)
webshot(url = html_file, file = img_file, delay = 0.1, vwidth = 1245)
> 简单reactablefmtr::save_reactable(x, "x.png")