webshot2::webshot()因文件系统权限问题无法完成截图
解决webshot2启动Chrome失败的权限问题
运行以下R代码时偶尔会失败,返回权限相关错误:
webshot2::webshot(url = "~/a_web_page.html", file = "~/an_image.png")
错误信息如下:
Error in launch_chrome(path, args) :
Failed to start chrome. Error: [1208/102720.412050:ERROR:filesystem_posix.cc(63)] mkdir /tmp/Crashpad/new: Permission denied (13)
[1208/102720.412409:ERROR:socket.cc(120)] recvmsg: Connection reset by peer (104)
更新:渲染包含HTML组件(如plotly图表)的R Markdown文件为Word输出时,同样会出现该错误。
可行的解决方法
- 自定义Chrome Crashpad临时目录:在调用webshot前,设置环境变量指定一个当前用户有写入权限的路径,同时确保目录存在:
Sys.setenv(CHROME_CRASHPAD_DIR = "~/chrome_crashpad") dir.create("~/chrome_crashpad", showWarnings = FALSE) # 再执行webshot命令 webshot2::webshot(url = "~/a_web_page.html", file = "~/an_image.png") - 修复
/tmp目录权限:检查并确保/tmp目录对当前用户开放读写权限,可通过以下命令修改(需管理员权限):sudo chmod 1777 /tmp - R Markdown场景适配:如果是渲染Rmd到Word时出错,在文档开头的设置块中添加环境变量配置:
之后再编写包含plotly等HTML组件的代码。--- title: "文档标题" output: word_document --- ```{r setup, include=FALSE} Sys.setenv(CHROME_CRASHPAD_DIR = "~/chrome_crashpad") dir.create("~/chrome_crashpad", showWarnings = FALSE)
内容的提问来源于stack exchange,提问作者Patrick
相关产品推荐
相关产品推荐

