I can export one graph at a time to a self-contained HTML file using RStudio's 'Export > Save as Web Page…'.
Thanks to Sergio Oller I can programatically export to an HTML file with a separate lib
directory like this:
p <- plotly::plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width)
htmltools::save_html(
html = htmltools::as.tags(
x = plotly::toWebGL(p),
standalone = TRUE),
file = "test.html")
However I'd like to be able to export a graph to a self-contained HTML file programatically so that I then can apply the same process to export many graphs to many files.