Rselenium can't connect to running shiny app
I figured it out with a LOT OF HELP from @jdharrison.
First make docker compose file (be careful with indentations - one indention must be 2 spaces) and save as docker-compose.yml
:
version: '2'services: ropensci: image: rocker/ropensci ports: - "8788:8787" links: - selenium:selenium - shiny:shiny selenium: image: selenium/standalone-chrome ports: - "4445:4444" links: - shiny:shiny shiny: image: rocker/shiny container_name: shiny volumes: - ~/Users/username/services/volumes/shiny/apps:/srv/shiny-server/ - ~/Users/username/services/volumes/shiny/logs:/var/log/ - ~/Users/username/services/volumes/shiny/packages:/home/shiny/
or download: https://codeshare.io/2j4yLB
then run docker-compose up
from folder where docker-compose.yml
file is.
- Add your apps to
/home/username/services/volumes/shiny/apps
- To navigate to your app from selenium use
http://shiny:3838/myapp
To check if it works you can save below code as app.R
in: ~/Users/username/services/volumes/shiny/apps/example/
:
library(shiny)server <- function(input, output) { output$distPlot <- renderPlot({ hist(rnorm(input$obs), col = 'darkgray', border = 'white') })}ui <- fluidPage( sidebarLayout( sidebarPanel( sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100) ), mainPanel(plotOutput("distPlot")) ))shinyApp(ui = ui, server = server)
and run:
library(RSelenium) remDr <- remoteDriver(remoteServerAddr = "selenium", port = 4444L, browser = "chrome") remDr$open()remDr$navigate(url = "http://shiny:3838/example")remDr$screenshot(display = TRUE)
There are a number of ways to achive this. Easiest way is to run docker in --net=host
mode. This will mean mean selenium server runs on the default port 4444
docker run -d --net=host selenium/standalone-chrome&
Your docker container will now have access to the HOST localhost.
To run on a non default PORT you can pass docker a selenium env variable:
docker run -d --net=host -e SE_OPTS="-port 4445" selenium/standalone-chrome