Export PNG files from Plotly to R without Internet

In this question Exporting PNG files from Plotly to R I asked how to export Plotly graphics to disk.

I used the plotly_IMAGE function, but the latter found that the function uses Plotly internet servers.

The question is that Plotly JavaScript is now local, how can I create a local png file without the Internet?

I tried this code without success:

 library(plotly) png(filename = "test.png") plot_ly(x = 1:10) dev.off() 

The idea is to make it programmatic, without clicking the export button on the chart.

+6
source share
2 answers

They added a new export function to the plotly package. But as far as I know, it does what @MLavoie offers the answer. Using:

 p <- plot_ly(...) export(p, file = "test.png") 
+3
source

You will need to install Phantom ( http://phantomjs.org/download.html ), which is pretty simple, and you can try the following:

 library(plotly) library(webshot) library(htmlwidgets) m <- plot_ly(x = 1:10) saveWidget(as.widget(m), "temp.html") webshot("temp.html", file = "test.png", cliprect = "viewport") 

You will find temp.html and temp.png in your working directory.

+2
source

All Articles