如何将 Highcharter 图保存为本地磁盘上的图像?
How to save a Highcharter plot as an image on local disk?
hc %>%
hc_add_series(name = "London", data = citytemp$london, type = "area") %>%
hc_rm_series(name = "New York")
我想将 hc
导出为 png 或 jpg。这可以通过选择导出 - 另存为图像来完成,但我想通过代码来完成,因为我有多个图要导出。我尝试了以下方法,但它返回了一个空白图像:
png('hc.png', width = 800,height = 400)
print(hc)
dev.off()
这应该可以通过 webshot 包实现(请参阅此处的问题:https://github.com/jbkunst/highcharter/issues/186)
library(webshot)
library(highcharter)
library(plyr)
data("citytemp")
plot <- highchart() %>%
hc_add_series(name = "London", data = citytemp$london, type = "area") %>%
hc_rm_series(name = "New York")
htmlwidgets::saveWidget(widget = plot, file = "~/plot.html")
setwd("~")
webshot::webshot(url = "plot.html",
file = "plot.png")
hc %>%
hc_add_series(name = "London", data = citytemp$london, type = "area") %>%
hc_rm_series(name = "New York")
我想将 hc
导出为 png 或 jpg。这可以通过选择导出 - 另存为图像来完成,但我想通过代码来完成,因为我有多个图要导出。我尝试了以下方法,但它返回了一个空白图像:
png('hc.png', width = 800,height = 400)
print(hc)
dev.off()
这应该可以通过 webshot 包实现(请参阅此处的问题:https://github.com/jbkunst/highcharter/issues/186)
library(webshot)
library(highcharter)
library(plyr)
data("citytemp")
plot <- highchart() %>%
hc_add_series(name = "London", data = citytemp$london, type = "area") %>%
hc_rm_series(name = "New York")
htmlwidgets::saveWidget(widget = plot, file = "~/plot.html")
setwd("~")
webshot::webshot(url = "plot.html",
file = "plot.png")