是否可以在RStudio服务器上的ShinyApp中运行RSelenium?

Ama*_*yan 5 r shiny shiny-server rselenium

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

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

rD<-rsDriver(port=4441L, browser="firefox", chromever=NULL, iedrver = NULL, phantomver = NULL)
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

因此服务器正在运行,但是无法打开浏览器

服务器日志为:

$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" 
Run Code Online (Sandbox Code Playgroud)

我的想法:在本地计算机上,我安装了浏览器,并且其路径存储在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")
Run Code Online (Sandbox Code Playgroud)

返回权限错误:

sh: ./firefox.exe: Permission denied
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:

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

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

非常感谢您的帮助)

da1*_*1an 1

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