Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically saving interactive graph in R to a specified location as a .html file

Tags:

r

I am using threejs library in R.

  library(threejs)
  z <- seq(-10, 10, 0.01)
  x <- cos(z)
  y <- sin(z)
scatterplot3js(x,y,z, color=rainbow(length(z)))

I need to save the interactive plot created by above commands as a.html file in a specified folder without using the drop down (in Rstudio) under viwer -> export which "save as web page".

Is there any R code for this?

like image 355
Artiga Avatar asked Oct 19 '15 10:10

Artiga


People also ask

How do I save a Plotly figure in HTML?

Any figure can be saved as an HTML file using the write_html method. These HTML files can be opened in any web browser to access the fully interactive figure.

What is the procedure to save graphs in R?

Plots panel –> Export –> Save as Image or Save as PDF It's also possible to save the graph using R codes as follow: Specify files to save your image using a function such as jpeg(), png(), svg() or pdf(). Additional argument indicating the width and the height of the image can be also used. Create the plot.

How do you share an interactive Plotly chart?

To share a plot from the Chart Studio Workspace, click 'Share' button on the left-hand side after saving the plot. The Share modal will pop-up and display a link under the 'Embed' tab. You can then copy and paste this link to your website. You have the option of embedding your plot as an HTML snippet or iframe.


1 Answers

Using htmlwidgets package you can do...

library(htmlwidgets)

dir.create("Z:\\new folder")

saveWidget(scatterplot3js(x,y,z, color=rainbow(length(z))), 
           file="Z:\\new folder\\scatterplot.html")
like image 76
Gaurav Avatar answered Nov 15 '22 07:11

Gaurav