html - R 中 htmlwidget 的 savewidget,无法将 html 文件保存在另一个文件夹中

标签 html r save htmlwidgets

我有一张 map 传单,我想将其保存在特定文件夹中的 html 文件中。 我正在使用 Windows 7。

我尝试了以下方法:

library(htmlwidgets)
saveWidget(map_leaflet, file="ressources/test.html")

library(htmlwidgets)
saveWidget(map_leaflet, file="ressources\\test.html")

library(htmlwidgets)
path_name <- file.path("ressources", "test.html", fsep="\\")
saveWidget(map_leaflet, file=path_name)

library(htmlwidgets)
path_name <- paste("ressources", "test.html", sep="/")
saveWidget(map_leaflet, file=path_name)

作为错误消息,根据 Rstudio session ,我有

1) setwd(dir) 错误:无法更改工作目录

2) 找不到路径

当我只这样保存时:

library(htmlwidgets)
saveWidget(map_leaflet, file="test.html")

它完美地工作。

预先感谢您的帮助。

最佳答案

同意。

这里有一个解决方法:

f<-"ressources\\test.html"
saveWidget(map_leaflet,file.path(normalizePath(dirname(f)),basename(f)))

问题似乎是 saveWidget 不适用于相对路径名,而 normalizePath 不适用于已存在的文件路径。

我认为这是 saveWidget 中的错误。

编辑:

我已经为 an existing open issue 贡献了我认为更好的解决方法

关于html - R 中 htmlwidget 的 savewidget,无法将 html 文件保存在另一个文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41399795/

相关文章:

r - 在 rmd 文件中保存和显示图

c# - 将图像保存在网络浏览器控件中,而无需从互联网上重新下载它们

android - 应用程序终止后无法保存我的首选项

html - 计算的宽度与指定的宽度有何不同?

R - 在 for 循环中打印对象名称

html - 跨度宽度在 CSS 中的省略号后不会减少

r - 将 dplyr summarise_at 与列索引一起使用

r - 2因素直方图分析

html - 无法对齐页脚中 p 旁边的链接

javascript - 配置 setinterval 函数以获得无限重复