Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export highchart widget as figure in R #186

Closed
Yang-Tang opened this issue Sep 21, 2016 · 5 comments
Closed

Export highchart widget as figure in R #186

Yang-Tang opened this issue Sep 21, 2016 · 5 comments
Labels

Comments

@Yang-Tang
Copy link

I'm wondering if there is any way to save a highchart htmlwidge as a figure (png or jpg) in R (Not through hc_exporting and js in brower).

@jbkunst
Copy link
Owner

jbkunst commented Sep 23, 2016

Hi @Yang-Tang ,

In this case you can use the webshot package https://github.com/wch/webshot, here's is an example to use with and arbitrary htmlwidget wch/webshot#10

@Yang-Tang
Copy link
Author

It's very helpful! Thank you @jbkunst for the suggestion!

@tbenschop
Copy link

Hi @jbkunst, It seems that for example the labels are not loaded:

HFI <- data.table(one=c(1:5),two=c(11:15),var=c('a','b','c','d','e'))
data_series<-list(list(name='#one',data=100*HFI$one,stack='Current',yaxis=0,
                       dataLabels=list(enabled=T,align= 'center',format= '{point.y:.1f}')),
                  list(name='#two',data=100*HFI$two,stack='Current',yaxis=0,
                       dataLabels=list(enabled=T,align= 'center',format= '{point.y:.1f}'))
)
abc<-  highchart() %>%
  hc_chart(type='column') %>%
  hc_xAxis(categories=unique(HFI$var)) %>%
  hc_add_series_list(data_series) #%>%
# hc_plotOptions()

## sample widget
library(mapview)
m <- mapview(breweries91)

## save to html
htmlwidgets::saveWidget(widget = abc, file = "~/map.html")
setwd("~")
## save html to png 
webshot::webshot(url = "map.html", 
                 file = "map.png")

Is there a way to fix that? I found some discussions about that over here but can't get it working in R...

@jbkunst
Copy link
Owner

jbkunst commented Dec 20, 2016

Mmm, I've not used weshot before, but try using the delay (https://cran.r-project.org/web/packages/webshot/vignettes/intro.html) parameter to wait to show the labels, not sure it will work but is it a try ;).

@tbenschop
Copy link

@jbkunst Thanks! WOrks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants