Saving and loading plotly objects in R

I have a list of plotly objects that I would like to save and be able to load from a potentially different R session. I have tried to use SaveRDS and readRDS and they work only if I load from the same R sesison that I saved the data in. Here is the error message i get when I try to load the list of plotly objects from a new R session.

Error in get(hash, envir = plotlyEnv) : 
object '00911d35a1db3b1c9554355#13' not found

Is there any way to do this in R?

1 Like

Hi @tdunn, before saving the plot, “build” the plot with plotly_build(), for example:

p <- plot_ly(x = rnorm(100)) %>% plotly_build()
saveRDS(p, "plot.rds")
d <- readRDS("plot.rds")

This was so useful, I was creating some relatively heavy plots in my shiny app and using this allowed me to speed up the site loading time significantly!