Comparing the size of the html widgets example page with the size of a self-contained html widget:
- when inspecting the example page, I'm getting a total of 717KB for the entire page
- when generating a self-contained html widget, I'm getting a ~3MB page that contains only the widget
# Code to generate the html widget
library(ggplot2)
library(plotly)
library(htmlwidgets)
p <- ggplot(data = diamonds, aes(x = cut, fill = clarity)) +
geom_bar(position = "dodge")
p <- ggplotly(p)
htmlwidgets::saveWidget(p, "path/to/my/widget.html", selfcontained = TRUE)
I'm trying to serve htmlwidgets to a web app over an HTTP API, so the size of these widgets is a concern. Why is the self-contained htmlwidget so much bigger than the htmlwidgets.org example page? Can I do something to change that?
Note: I'm considering generating a non-self-contained html page, splitting the page to get the data, and serving the *.min.js
files but the aggregated js files still add up to a few MB.