Skip to contents

Plotly htmlwidgets capture parent environments in closures, causing 60-80x size inflation when serialized via saveRDS/targets. This function runs plotly_build() to resolve lazy data, then replaces closure environments with emptyenv() to eliminate the bloat.

Usage

strip_plotly(p)

Arguments

p

A plotly htmlwidget object

Value

The same plotly object with closures stripped (much smaller on disk)

Examples

if (FALSE) { # \dontrun{
p <- plotly::plot_ly(mtcars, x = ~mpg, type = "histogram")
object.size(p)       # large
p2 <- strip_plotly(p)
object.size(p2)      # small
} # }