我有一张 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/