Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument "selfcontained" deprecated in htmlwidgets::saveWidget()

I keep getting [WARNING] Deprecated: --self-contained. use --embed-resources --standalone when saving a plotly plot as a self-contained html widget, using htmlwidgets::saveWidget(..., selfcontained = TRUE).

I can't figure out how to use "embed-resources" or "standalone" as arguments in the function. This just recently started, wondering if anyone else has had this warning occur, or knows the proper arguments to use for this. Updated RStudio and the package, but the warning persists.

Using R 4.2.1, RStudio 2022.07.2+576 "Spotted Wakerobin", htmlwidgets 1.5.4.

library(plotly)
library(htmlwidgets)

fig <- plot_ly(x = 1:10, y = 1:10, type = "scatter", mode = "lines")
htmlwidgets::saveWidget(partial_bundle(fig), file = "plotly.html", selfcontained = TRUE)
utils::browseURL("plotly.html")
like image 506
bt3 Avatar asked Apr 28 '26 22:04

bt3


2 Answers

That's a Pandoc change in version 2.19. You can see what version you're using with htmlwidgets:::pandoc_available(); htmlwidgets:::.pandoc$version. I think RStudio distributes version 2.18, but they may have updated, or you may have installed it separately.

The Pandoc change log is here: https://pandoc.org/releases.html .

I don't think there's any way to fix that other than editing the htmlwidgets source. Maybe this will be fixed in the next release?

EDITED to add: This change has been handled in rmarkdown for a while, but htmlwidgets was calling Pandoc directly. The next release (1.6.0) of htmlwidgets will fix it by letting rmarkdown handle the call. This should also future-proof it a bit.

I've since found a workaround to produce a standalone .html file with no "files" folder: Set your working directory to where you'd like to output the .html, Then write your widget (fig, here) to the working directory:

setwd(myplotdir)
htmlwidgets::saveWidget(as_widget(fig),
                            paste0("./", plot.name),
                        selfcontained = TRUE)
setwd(myoriginalwd)

This results in a standalone .html for me, interestingly.

like image 22
bt3 Avatar answered Apr 30 '26 11:04

bt3