Reputation: 147
How to export a highchart (type = 'organization') to PNG image in R?
Here is an example:
library(highcharter)
library(tidyverse)
highchart() %>%
hc_chart(type = 'organization') %>%
hc_add_series(
data = list(
list(from = 'A', to = 'A1'),
list(from = 'A', to = 'A2')
))
I tried as follows, but the exported file is empty:
library(highcharter)
library(tidyverse)
png("org.png")
highchart() %>%
hc_chart(type = 'organization') %>%
hc_add_series(
data = list(
list(from = 'A', to = 'A1'),
list(from = 'A', to = 'A2')
))
dev.off()
Upvotes: 1
Views: 1587
Reputation: 1726
You can use the package webshot to achieve that. Read more about on Export highchart widget as figure in R.
EDIT: The answer worked for the OP using webshot2, which is meant to replace webshot.
library(highcharter)
library(tidyverse)
library(webshot)
org <- highchart() %>%
hc_chart(type = 'organization') %>%
hc_add_series(
data = list(
list(from = 'A', to = 'A1'),
list(from = 'A', to = 'A2')
))
htmlwidgets::saveWidget(widget = org, file = "org.html")
getwd()
webshot(url = "org.html",
file = "org.png",
delay=3) # delay will ensure that the whole plot appears in the image
dev.off()
Upvotes: 1