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")