ABSTRACT

Any widget made from any htmlWidgets package (e.g., plotly, leaflet, DT, etc.) can be saved as a standalone HTML file via the htmlwidgets::savewidget() function. By default, it produces a completely selfcontained HTML file, meaning that all the necessary JavaScript and CSS dependency files are bundled inside the HTML file. This makes it very easy to share a widget as a single HTML file. In this case, consider using the partial_bundle() function to reduce the size of the bundled files. By default, it automatically determines a reduced version of plotly.js that is sufficient for rendering your graphic. This can lead to a substantial reduction in the overall file size, especially if you’re using basic chart types: p <- plot_ly(x = 1:10, y = 1:10) %>% add_markers() widget_file_size <- function(p) {   d <- tempdir()   withr:: with_dir(d, htmlwidgets ::saveWidget(p, "index.html"))   f <- file.path(d, "index.html")   mb <- round(file.info(f) $size / 1e6, 3)   message("File is: ", mb," MB") } widget_file_size(p) #> File is: 3.495 MB widget_file_size(partial_bundle(p)) #> File is: 1.068 MB