Flecflec
Flecflec

Reputation: 243

RStudio : what is the code behind the export>save as image button?

I try to find a way to save a plotly graph as png without installing orca (I'm not allowed to).
It appears that if I plot my graphics, lets say :

library(dplyr)
library(plotly)
p <- plot_ly(z = ~volcano) %>% add_surface()
p

and then clic on export>save as image>Save as png, the resulting static plot is available on my computer

1]

But If I try to use classical png() like this :

png("myvolcano.png")
plot_ly(z = ~volcano) %>% add_surface()
dev.off()

I get a blank png... (while it's working for a classical plot(1) )

How to reproduce by code what I get from the menu bar ?

Thank you!

Upvotes: 2

Views: 492

Answers (1)

Gi_F.
Gi_F.

Reputation: 961

Hi this is more a comment than an answer but my reputation does not allow me to comment.

You can use 2 strategies to export plotly graphs:

  • use orca() function in the plotly pkg (if you ?orca will find all the explanations)
  • use htmlwidgets::saveWidget(p, file = "myvolcano.html") which downloads in html format

In the past there was a function export() but it is deprecated now. Hope this helps.

Upvotes: 1

Related Questions