How to save a Highcharter plot as an image on local disk?

折月煮酒 提交于 2021-02-04 07:37:44

问题


hc %>% 
  hc_add_series(name = "London", data = citytemp$london, type = "area") %>% 
  hc_rm_series(name = "New York")

I want to export hc as a png or jpg. This can be done by selecting Export - Save as Image but I'd like to do it through codes because I have multiple plots to export. I have tried the followings but it returned a blank image:

png('hc.png', width = 800,height = 400)
print(hc)
dev.off()

回答1:


This should be possible with the webshot package (see question here: 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")



来源:https://stackoverflow.com/questions/59885304/how-to-save-a-highcharter-plot-as-an-image-on-local-disk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!