savewidget from htmlwidget in R , cannot save html file in another folder

我们两清 提交于 2019-11-30 01:33:01

问题


I have a map leaflet that I want to save in an html file in a specific folder. I am using Windows 7.

I tried the following :

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)

As an error message, depending on the Rstudio session, I either have

1) Error in setwd(dir) : cannot change working directory

2) Cannot find path

When I only save like this :

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

It works perfectly.

Thank you in advance for your help.


回答1:


Agreed.

here is a workaround:

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

The issues appear to be that saveWidget does not work with relative pathnames and normalizePath does not work for paths to files that done exist yet.

I would call this a bug in saveWidget.

edit:

I have contribute what I think is an even better workaround to an existing open issue



来源:https://stackoverflow.com/questions/41399795/savewidget-from-htmlwidget-in-r-cannot-save-html-file-in-another-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!