【问题标题】:Is it possible to run RSelenium in ShinyApp on the RStudio server?是否可以在 RStudio 服务器上的 ShinyApp 中运行 RSelenium?
【发布时间】:2018-10-25 06:44:12
【问题描述】:

我遇到了这样一个问题:我有使用 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。如果我将这两个词放在一个搜索查询中,结果大致相同。

非常感谢您的帮助)

【问题讨论】:

  • 我有同样的问题,虽然我没有将它用于 ShinyApp。我遇到了同样的问题——因为 R 脚本是通过 R 服务器运行的(而不是在我的机器上本地运行),并且 Chrome 没有安装在服务器上,它似乎不知道该怎么做。我已将此帖子添加为书签,希望有人能提供帮助!
  • @LakshyaAg 因为您不是 OP,您能否阐明您的目标和挑战。我的意思是,“服务器”只是另一台以 Linux 作为操作系统的计算机。所以可以关注rpubs.com/johndharrison/RSelenium-Docker 来安装 rselenium。如果该部分有效,可以查看是否必须调整来自闪亮的调用,...
  • @TonioLiebrand 您好,感谢您的回复。我想按照 OP 的方式设置一些东西。基本上,我对应用程序的想法是从用户那里获取输入,爬取一些页面(使用 RSelenium)并将该数据返回给 Shiny,然后我将使用它来填充选项和其他东西。

标签: r shiny shiny-server rselenium


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

【讨论】:

    猜你喜欢
    • 2021-11-17
    • 1970-01-01
    • 2015-08-25
    • 2017-04-05
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多