首页 > 解决方案 > 是否可以在 RStudio 服务器上的 ShinyApp 中运行 RSelenium?

问题描述

我遇到了这样一个问题:我有使用 RSelenium 导航页面、单击按钮和收集数据的 Rscript。我将此脚本作为一个函数包含在我的 shinyApp 中。当我从我的机器上运行它时,一切都按预期进行:单击按钮后 firefox 启动并正确运行。

当我想在我公司的 Rstudio 服务器(Linux 下)上发布脚本以便通过链接提供对工具(在 Windows 下编写)的访问时,出现了问题。运行后:

rD<-rsDriver(port=4441L, browser="firefox", chromever=NULL, iedrver = NULL, phantomver = NULL)

A 接收此输出:

    $client
[1] "No sessionInfo. Client browser is mostly likely not opened."
$server
Process Handle
command   : /tmp/RtmpElIBko/file3a0241d505d8.sh 
system id : 15293
state     : exited

所以服务器正在运行,但无法打开浏览器

服务器日志是:

$stderr
 [1] "14:22:06.908 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.12.0', revision: '7c6e0b3'"                                                                                        
 [2] "14:22:06.910 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4441"                                                                                              
 [3] "2018-05-15 14:22:07.026:INFO::main: Logging initialized @452ms to org.seleniumhq.jetty9.util.log.StdErrLog"                                                                                     
 [4] "14:22:07.227 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4441"                                                                                                       
 [5] "14:22:08.467 INFO [ActiveSessionFactory.apply] - Capabilities are: Capabilities {browserName: firefox, javascriptEnabled: true, nativeEvents: true, version: }"                                 
 [6] "14:22:08.469 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.firefox.GeckoDriverService)"
 [7] "1526383328500\tgeckodriver\tINFO\tgeckodriver 0.20.1"                                                                                                                                           
 [8] "1526383328506\tgeckodriver\tINFO\tListening on 127.0.0.1:30716"                                                                                                                                 
 [9] "1526383328777\tmozrunner::runner\tINFO\tRunning command: \"/usr/bin/firefox\" \"-marionette\" \"-profile\" \"/tmp/rust_mozprofile.KCqtcRfWkHTS\""                                               
[10] "No protocol specified"                                                                                                                                                                          
[11] "Error: cannot open display: :0" 

我的想法:在本地机器上我安装了浏览器,它的路径存储在PATH变量中。我在服务器中什么都没有,所以不清楚应该打开什么。

我试图做的事情:此时我正在等待我的 IT 部门在服务器上安装浏览器(我什至不知道这听起来是不是很疯狂),因为我没有权限。我将 Mozilla 浏览器从我的计算机上传到服务器并运行这样的代码来启动没有 RSelenium 的浏览器,直接:

  system('java -Dwebdriver.firefox.bin="\\R\\Wordstat Yandex\\Mozilla\\firefox.exe"')
  system('java -Dwebdriver.gecko.driver,"R\\Wordstat Yandex\\geckodriver"')
  system('export PATH=$PATH:"\\R\\Wordstat Yandex\\Mozilla\\firefox.exe"')
  system("./firefox.exe")

返回权限错误:

sh: ./firefox.exe: Permission denied

所以我的问题是:

  1. 是否可以在服务器上安装浏览器(我复制了文件夹,可能是错误的)
  2. 如果第 1 点的答案是“是”,那么应该如何正确完成(即,是否应该安装 linux 版本的 firefox?)
  3. 如果答案是“否”,那么还有其他方法可以在 Rstudio 服务器的 shinyapp 中运行基于 Rselenium 的脚本(假设它在本地的 shinyapp 中工作)

此时我在 Google 中看到的是如何使用 RSelenium 测试 shinyapp。如果我将这两个词放在一个搜索查询中,结果大致相同。

非常感谢您的帮助)

标签: rshinyshiny-serverrselenium

解决方案


  1. 您的服务器可能已经安装了浏览器,但这可能不是问题所在
  2. 如果服务器没有安装浏览器,则安装它的命令因 Linux 发行版而异,但您可以通过谷歌搜索找到,例如“安装 firefox ubuntu”或“安装 firefox redhat 8”(我不会浪费我的时间追逐这个线程)。
  3. 要求 IT 安装 RSelenium 服务器:https ://cran.r-project.org/web/packages/RSelenium/vignettes/basics.html并帮助您进行设置。如果您没有对服务器的 root 访问权限,那么您将束手无策,您必须希望 IT 能够帮助您。

推荐阅读