-
Notifications
You must be signed in to change notification settings - Fork 627
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
Save Locally Generated Plot Locally As PNG/JPG #311
Comments
Hmm, You can also open the interactive viz in a web browser and use plotly's "download as plot png" button (this isn't yet working in RStudio, but we're working on it) |
Here is a SO related post: exporting png files from plotly in r without internet connection |
You could use something like RSelenium to automate this, but I won't be adding any native support to plotly's R package. |
does plotly_IMAGE only work with username and api_key? |
@xzmagic unfortunately yes. The conversion is created in Plotly server, not locally. |
@timelyportfolio bootstrapping off of discusion in plotly/plotly.js#83, what do you think about using https://github.com/jeroenooms/rsvg to produce bitmaps locally? |
(of course I'd prefer avoiding an extra R dependency if a pure JS solution seems plausible) |
Funny, I had the same idea this morning :) I started yesterday on very preliminary work to attach the Remember though also the newest |
That'd be great! |
Here are two ways of accomplishing a static image of a Plotly graph. If using in
Method #2 has the advantage of multiple export formats. Webshot
Shiny gadgets and
|
Thanks @timelyportfolio. I think for now we'll just leave this be and hope plotly.js provides a solution. For the record, I think I prefer the webshot approach, but I don't want to depend on it. |
Quick PSA 🎤 @yankev is is adding programmatic offline export support to the Python client in this PR: @spencerlyon2 has added incredible offline image export for the Julia client described here: |
I will try to add this in over next couple of days. |
@timelyportfolio can we get away with export without a full-blown DOM renderer? I've added this function to the major update I've been working on locally (I'll start the pull request tomorrow probably). What do you think? #' Export a plotly graph to a static file
#'
#' @param p a plotly or ggplot object.
#' @param file a filename. See the file argument of \code{webshot::webshot}
#' for valid extensions.
#' @param ... arguments passed onto \code{webshot::webshot}
#' @export
#' @examples \dontrun{
#' export(plot_ly(economics, x = ~date, y = ~pce))
#' }
export <- function(p, file = "plotly.png", ...) {
if (system.file(package = "webshot") == "") {
stop(
'Please install the webshot package ',
'(if not on CRAN, try devtools::install_github("wch/webshot"))'
)
}
f <- basename(tempfile('plotly', '.', '.html'))
on.exit(unlink(f), add = TRUE)
html <- htmlwidgets::saveWidget(plotly_build(p), f)
webshot::webshot(f, file, ...)
} |
I don't see any way possible to export without a full-blown DOM renderer. Excited to see your changes. |
Closed via d2bf2a1. |
How can I save an interactive plot generated by plotly locally as png? The commands png()...dev.off() won't capture the plot command and the function call plotly_IMAGE throws an authorization error although the plot is generated locally and I'm logged in.
Thanks for your help.
The text was updated successfully, but these errors were encountered: