R中的htmlwidget中的savewidget无法将html文件保存在另一个文件夹中 [英] savewidget from htmlwidget in R , cannot save html file in another folder

查看:1097
本文介绍了R中的htmlwidget中的savewidget无法将html文件保存在另一个文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张地图宣传单,我想将它保存在特定文件夹的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)
$ b $ library(htmlwidgets)
path_name< - paste(ressources,test.html,sep =/ )
saveWidget(map_leaflet,file = path_name)

作为错误消息,取决于Rstudio会话,我要么有

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中的一个错误。



编辑:



我认为这是一种更好的解决方法,它可以帮助一个现存的开放问题


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.

解决方案

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

这篇关于R中的htmlwidget中的savewidget无法将html文件保存在另一个文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆