Saves a plotly/htmlwidget object, a list of them, or an HTML tag list to an HTML file. The output can optionally be made self-contained by embedding all dependencies inline with Pandoc.
Arguments
- plots
What to save. One of:
a single
htmlwidget(e.g. aplotlyobject) or HTML tag,a list of
htmlwidgetobjects / tags,an existing
shiny.tag.list.
A single object is wrapped into a length-1 list; anything that is not already a
shiny.tag.listis coerced viahtmltools::tagList().- file
[character(1)]Path to the output HTML file.- selfcontained
[logical(1)]Embed all dependencies into a single self-contained file? Requires Pandoc. DefaultTRUE.- libdir
[character(1) | NULL]Directory for the HTML dependency files, resolved relative tofile's directory (or absolute). WhenNULL, defaults to"<file basename>_files"next tofile. Pass the same value (e.g."lib") for several files saved into one directory to share a single dependency folder between them. Removed after embedding whenselfcontained = TRUE.
Examples
if (FALSE) { # interactive()
p1 <- plotly::plot_ly(mtcars, x = ~mpg, y = ~wt)
p2 <- plotly::plot_ly(mtcars, x = ~mpg, y = ~hp)
# a single widget ...
save_plots(p1, tempfile(fileext = ".html"), selfcontained = FALSE)
# ... or a list of them
save_plots(list(p1, p2), tempfile(fileext = ".html"), selfcontained = FALSE)
}