# NOT RUN {
# The webshot package handles non-WebGL conversion to jpeg/png/pdf
# }
# NOT RUN {
export(plot_ly(economics, x = ~date, y = ~pce))
export(plot_ly(economics, x = ~date, y = ~pce), "plot.pdf")
# svg/webp output or WebGL conversion can be done via RSelenium
if (requireNamespace("RSelenium")) {
rD <- RSelenium::rsDriver(browser = "chrome")
export(
plot_ly(economics, x = ~date, y = ~pce), "plot.svg", rD
)
export(
plot_ly(economics, x = ~date, y = ~pce, z = ~pop), "yay.svg", rD
)
}
# If you can't get a selenium server running, another option is to
# use Plotly.downloadImage() via htmlwidgets::onRender()...
# Downloading images won't work inside RStudio, but you can set the viewer
# option to NULL to prompt your default web browser
options(viewer = NULL)
plot_ly(economics, x = ~date, y = ~pce, z = ~pop) %>%
htmlwidgets::onRender(
"function(el, x) {
var gd = document.getElementById(el.id);
Plotly.downloadImage(gd, {format: 'png', width: 600, height: 400, filename: 'plot'});
}"
)
# }
Run the code above in your browser using DataCamp Workspace