The code below creates a plot in the Viewer window, but it saves it as a blank png of size 318 bytes. I tried with 'browsable' instead of 'html_print' but got the same behavior. Also tried with saveWidget + webshot without success (as in [Save viewer object rendered in RStudio as image]).
Is there any way of saving the Viewer plot as a png automatically (without opening File Explorer or clicking on any action button)?
Thank you
library(htmltools)
png("Rplot.png")
html_print(tags$div(
id = "myDiv",
tags$head(HTML("<script src='https://cdn.plot.ly/plotly-2.12.1.min.js'></script>")),
tags$script(HTML("
var trace1 = { x: [1, 2, 3, 4], y: [10, 15, 13, 17], type: 'scatter' };
var trace2 = { x: [1, 2, 3, 4], y: [16, 5, 11, 9], type: 'scatter' };
var data = [trace1, trace2];
Plotly.newPlot('myDiv', data);"))
))
Sys.sleep(1)
dev.off()