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

saving plotly plots locally? #294

Closed
vinhdizzo opened this issue Nov 6, 2015 · 9 comments
Closed

saving plotly plots locally? #294

vinhdizzo opened this issue Nov 6, 2015 · 9 comments

Comments

@vinhdizzo
Copy link

Hi,

When I plot outside of RStudio, the visualization opens on the default browser. The relevant files are located in a temporary location. What's the proper way to save the interactive visually locally? That is, analogous to the pdf and png functions in R. Would like to do that in order to embed elsewhere.

Thank you.

@cpsievert
Copy link
Collaborator

cpsievert commented Nov 7, 2015

You can save a plot as standalone HTML with htmlwidgets::saveWidget()

library(plotly)
p <- plot_ly(mtcars, x = ~mpg, y = ~disp, mode = "markers")
htmlwidgets::saveWidget(p, "index.html")

Another option is to use Export -> Save as Web Page in the RStudio viewer

screen shot 2015-11-07 at 1 12 44 pm

If you want to save a plot as png/pdf/svg/etc, have a look at plotly_IMAGE() or export()

@vinhdizzo
Copy link
Author

Thanks @cpsievert , htmlwidgets::saveWidget is precisely what I was looking for.

@bextra
Copy link

bextra commented Nov 18, 2016

FYI, there is a warning message that contradicts the above statement

p = plotly::plot_ly(df, x = df$variable, y = df$value, color = df$name, hoverinfo = "text", type = "bar", colors = "Set1", text = paste(df$name, "\t", " Abundance:", df$value, "\t", " Sample: ", df$variable)) %>%
plotly::layout(barmode = "stack", hovermode = "closest", margin = m_template, xaxis = x, yaxis = y)

htmlwidgets::saveWidget(as.widget(p), file = "stacked_bar_scaled.html")
Warning message:
'as.widget' is deprecated.
Use 'plot_ly' instead.
See help("Deprecated") 

@cpsievert
Copy link
Collaborator

Thanks @kbeck527, as.widget() isn't necessary anymore -- I've updated the comment

@Victsz
Copy link

Victsz commented Jan 23, 2017

Running out of memory while plotting 200k+ points. And I tried editbin /LARGEADDRESSAWARE to fix ref to https://jonathanchang.org/coding/fixing-pandoc-out-of-memory-errors-on-windows/ , but still same problem.

Open web page locally and copy the temp html file instead of using htmlwidgets is fine, so if there is a way to get the temp local file URL by some function calls such that I don`t have to run htmlwidgets.

  • p<-subplot(mergerd, nrows = length(mergerd),shareX = T)
  • htmlwidgets::saveWidget(p,'test.html')

pandoc.exe: Out of memory
Error: pandoc document conversion failed with error 251
In addition: Warning message:
running command 'C:/PROGRA~2/Pandoc/pandoc +RTS -K512m -RTS C:\Users\victor\Documents\Stash\bumblebee\BumblebeeR\Bumblebee\Bumblebee\test.html --from markdown --output C:\Users\victor\Documents\Stash\bumblebee\BumblebeeR\Bumblebee\Bumblebee\test.html --self-contained --template C:\Users\victor\AppData\Local\Temp\1\RtmpyuOMkE\file3c05b6878d2.html' had status 251

  • p<-subplot(mergerd, nrows = length(mergerd),shareX = T)
  • htmlwidgets::saveWidget(p,'test.html')

pandoc.exe: Out of memory
Error: pandoc document conversion failed with error 251
In addition: Warning message:
running command 'C:/PROGRA~2/Pandoc/pandoc +RTS -K512m -RTS C:\Users\victor\Documents\Stash\bumblebee\BumblebeeR\Bumblebee\Bumblebee\test.html --from markdown --output C:\Users\victor\Documents\Stash\bumblebee\BumblebeeR\Bumblebee\Bumblebee\test.html --self-contained --template C:\Users\victor\AppData\Local\Temp\1\RtmpyuOMkE\file3c05b6878d2.html' had status 251

@jankuc
Copy link

jankuc commented Feb 10, 2017

You can also save it as a png, jpeg or pdf file by using export():

p <- plot_ly(...)
export(p, file='image.png')

@ghost
Copy link

ghost commented Mar 1, 2017

p <- plot_ly(...) export(p, file='image.png')

does not work as it says : Webgl is not supported by browser. But the browser I use does support Webgl. I however also installed phantomjs too!

How does it work for you?

@Sergeich11
Copy link

htmlwidgets::saveWidget(as_widget(p), file = "test_plotly_widget.html") worked for me (CRAN plotly version, RStudio 1.0.143). Frustratingly, plotly commands work in R console to produce charts viewable in Explorer but in RStudio I get just the axes and no data plotted. Saving as html does not work in R console (requires pandoc) but works from RStudio.

@qaiseri79
Copy link

qaiseri79 commented Aug 17, 2017

Is it possible for saveWidget to add custom js file for plotly to add some aditional custom functionality.

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

No branches or pull requests

7 participants