Save Plotly as Static Graph

Hi,

I'm exploring a function with waterfall chart.
The original version is based on plot_ly interactive version.

Example:
fig <- plot_ly( data,
type = "waterfall",
measure = ~measure,
x = ~x,
textposition = "outside",
y= ~y)

But, I'd also want to save the same chart as a static png/jpeg image.
Found that orca package can help w/ that:
orca(fig, "Static Image.png", width = 7 * 300, height = 4 * 300)

Yet, it is not intuitive enough & does not seem to collaborate w/ RStudio Cloud.
Wondered if anyone knows an easier way to save static plot_ly charts & specify resolution?
Thanks!

I use webshot (which relies on phantomJS, to render a widget as a webpage, and screen shot it)

library(plotly)
# renv::install("webshot")
# webshot::install_phantomjs()

library(webshot)
library(htmlwidgets)

x= list("Sales", "Consulting", "Net revenue", "Purchases", "Other expenses", "Profit before tax")
measure= c("relative", "relative", "total", "relative", "relative", "total")
text= c("+60", "+80", "", "-40", "-20", "Total")
y= c(60, 80, 0, -40, -20, 0)
data = data.frame(x=factor(x,levels=x),measure,text,y)

fig <- plot_ly( data,
                type = "waterfall",
                measure = ~measure,
                x = ~x,
                textposition = "outside",
                y= ~y,
                width = 2100,
                height= 1200)

saveWidget(as_widget(fig), "temp.html")
webshot("temp.html", file = "test.png")
file.remove("temp.html")

Thanks, @nirgrahamuk !
I tried this approach.
Code creates temp.file for me, but the temp.png appears to be empty.
Maybe orca is the only option for now.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.