使用
[WARNING] Deprecated: --self-contained. use --embed-resources --standalone
将绘图保存为独立的 html 小部件时,我不断收到 htmlwidgets::saveWidget(..., selfcontained = TRUE)
。
我不知道如何在函数中使用“嵌入资源”或“独立”作为参数。这只是最近开始的,想知道是否有其他人发生过此警告,或者知道为此使用的正确参数。更新了 RStudio 和软件包,但警告仍然存在。
使用 R 4.2.1、RStudio 2022.07.2+576“斑点 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")
这是 2.19 版本中的 Pandoc 更改。您可以使用
htmlwidgets:::pandoc_available(); htmlwidgets:::.pandoc$version
查看您正在使用的版本。我认为 RStudio 发布了 2.18 版本,但他们可能已经更新,或者您可能已经单独安装了它。
Pandoc 变更日志在这里:https://pandoc.org/releases.html .
我认为除了编辑
htmlwidgets
源代码之外,没有任何方法可以解决这个问题。也许这会在下一个版本中修复?
编辑添加:此更改已在
rmarkdown
中处理了一段时间,但 htmlwidgets
直接调用 Pandoc。 htmlwidgets
的下一个版本 (1.6.0) 将通过让 rmarkdown
处理呼叫来修复此问题。这也应该是面向未来的。
此后,我找到了一种解决方法来生成没有“文件”文件夹的独立
.html
文件:将工作目录设置为您想要输出 .html
的位置,然后编写您的小部件(fig
,此处)到工作目录:
setwd(myplotdir)
htmlwidgets::saveWidget(as_widget(fig),
paste0("./", plot.name),
selfcontained = TRUE)
setwd(myoriginalwd)
有趣的是,这对我来说是一个独立的
.html
。