savewidget from htmlwidget in R , cannot save html file in another folder(来自 R 中 htmlwidget 的 savewidget,无法将 html 文件保存在另一个文件夹中)
问题描述
我有一个地图传单,我想将它保存在特定文件夹中的 html 文件中.我正在使用 Windows 7.
I have a map leaflet that I want to save in an html file in a specific folder. I am using 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 会话,我有
As an error message, depending on the Rstudio session, I either have
1) setwd(dir) 中的错误:无法更改工作目录
1) Error in setwd(dir) : cannot change working directory
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 不适用于已存在的文件的路径.
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.
我认为这是 saveWidget 中的一个错误.
I would call this a bug in saveWidget.
我为一个现有的未解决问题贡献了我认为更好的解决方法
I have contribute what I think is an even better workaround to an existing open issue
这篇关于来自 R 中 htmlwidget 的 savewidget,无法将 html 文件保存在另一个文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:来自 R 中 htmlwidget 的 savewidget,无法将 html 文件保存在另一个文件夹中
基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
