Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run RSelenium in ShinyApp on the RStudio server?

I faced such an issue: i have Rscript that uses RSelenium to navigate pages, click buttons and collect data. I included this script as a function in my shinyApp. When I run it from my machine everything is as expected: after clicking the button firefox launches and process in running corretly.

The trouble occured when I wanted to publish script on Rstudio server (under Linux) in my company in order to provide access to the tool (written under Windows) by link. After running this:

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

A receive this output:

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

So the server is running, but browser can't be opened

server log is:

$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" 

My thoughts: on local machine I had browser installed and it's path is stored in PATH variable. I had nothing in the server, so it is unclear what should be opened.

What I tried to do: by this time i'm waiting for my IT department to install the browser on server (I even don't know whether it sounds like madness) because I have no permissions. I uploaded Mozilla browser from my computer to the server and ran such a lines to launch browser without RSelenium, directly:

  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")

which returns permission error:

sh: ./firefox.exe: Permission denied

So my questions are:

  1. Is it possible to install browser on server (I copied folder and probably is was wrong)
  2. If answer for point 1 is "yes' then how it should be done corretly (i.e, should it be linux ver. of firefox installed?)
  3. If answer is "no" then are there any other ways to run Rselenium based scripts within shinyapp from Rstudio server (assumning it works in shinyapp locally)

By this time what I saw in Google was how to test shinyapp using RSelenium. If i put both these words in one search query the result is approximately the same.

Many thanks for any help)

like image 630
Amaliya Akopyan Avatar asked Sep 05 '25 03:09

Amaliya Akopyan


1 Answers

  1. Your server probably already has a browser installed, but this is likely not the problem
  2. If the server doesn't have a browser installed, then the command for installing it varies by Linux distribution, but you can find out by googling e.g. "install firefox ubuntu" or "install firefox redhat 8" (I wouldn't waste my time chasing this thread).
  3. Ask IT to install RSelenium Server: https://cran.r-project.org/web/packages/RSelenium/vignettes/basics.html and help you get set up. If you don't have root access to the server, then your hands are tied and you have to hope IT will help you.
like image 114
da11an Avatar answered Sep 08 '25 02:09

da11an