我正在尝试将一些交互式图形保存到额外的文件中。这适用于 htmlwidget::saveWidget
。但是我将它们保存到不同的文件夹中会遇到问题,例如结果文件夹。
results_dir <- 'results'
if(!dir.exists(results_dir)) dir.create(results_dir)
p <- plotly::plot_ly(economics, x = ~date, y = ~pop,
type = 'scatter', mode = 'markers')
htmlwidgets::saveWidget(p,
file.path(results_dir, 'VSGs.html'))
错误信息是:
Error in normalizePath(basepath, "/", TRUE) :
path[1]="results": No such file or directory
有人知道发生了什么吗?
我知道之后只是移动文件,但我希望解决此错误消息。
htmlwidgets::saveWidget(p, 'VSGs.html')
file.rename('VSGs.html', file.path(results_dir, 'VSGs.html'))
最佳答案
“结果”似乎不是有效路径
尝试设置存在的文件夹的完整路径。
这应该工作:
dir.create(paste0(getwd(),"/results"))
results_dir = paste0(getwd(),"/results") # get directory
然后使用 results_dir 作为保存路径。
关于r - 使用 htmlwidget 将交互式绘图保存到路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48690837/