Saving plot_ly object as .rds file and displaying in separate computer

Hello!

I am building a shiny app from an .Rmd file which mainly displays some animations and plots. To make the shinyapps.io page load faster I’ve made all the plot_ly objects locally, store them and then simply load and display them on the shiny server side.

Illustration
In local script:

p = economics %>% plot_ly(x = ~pop, y = ~pce, type = "scatter", mode = "markers")
saveRDS(p, "plot.rds")

In shiny server:

p = readRDS("plot.rds")
p

And then hope that gets displayed (but it does not). Instead, I get the following in my shinyapps.io log:

Warning: Error in value[[3L]]: Couldn't normalize path in `addResourcePath`, with arguments: `prefix` = 'jquery-1.11.3'; `directoryPath` = '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/crosstalk/lib/jquery'

I have seen in other internet posts that this is a problem to do with the plot_ly object dependencies and there are some tedious workarounds using htmlwidgets which I have failed to use.

Has anybody managed to make this work? Any help/discussion is appreciated.

1 Like

I have had this as well. For what its worth, I was created the plot and put it into an .rds file in windows. Then, I read the file in macOS and while the plot shows in the Rstudio preview, the bookdown html and pdf outputs show either a blank space or only the legend. Very strange.

I’d use htmlwidgets::saveWidget(partial_bundle(fig), "fig.html", selfcontained = TRUE) to save the plot as a html file, put it in shiny’s www-dir and display it in an iframe.