I configured selenium server in docker. It works ok - I can connect to it, but when I want to interact with running local shiny app Rselenium does not see it. Details below:
I did step-by-step:
I run selenium server:
docker run -d -p 4445:4444 selenium/standalone-chrome
successfully connected to selenium server:
remDr <- remoteDriver(remoteServerAddr = "localhost"
, port = 4445L
, browserName = "chrome"
, platform = "MAC")
> remDr$open()
[1] "Connecting to remote server"
> shiny::runApp(file.path(find.package("RSelenium"), "apps", "shinytestapp"), port = 6012)
Listening on http://127.0.0.1:6012
remDr$navigate("localhost:6012")
appTitle <- remDr$getTitle()[[1]]
expect_equal(appTitle, "Shiny Test App")
and got error:
Error: 'appTitle' not equal to "Shiny Test App".
1/1 mismatches
x[1]: "localhost"
y[1]: "Shiny Test App"
remDr$screenshot(display = TRUE)
and it looks like this:
Do you have idea why RSelenium does not see shiny app running locally?
But the simplest way to run a Shiny app is to run it locally. You only need the shiny R package installed, and you can run the app in your browser.
Open the app. R script in your RStudio editor. RStudio will recognize the Shiny script and provide a Run App button (at the top of the editor). Either click this button to launch your app or use the keyboard shortcut: Command+Shift+Enter (Control+Shift+Enter on Windows).
Automatically stop a Shiny app when closing the browser tabBy adding a single line to the server code session$onSessionEnded(stopApp) , a Shiny app will automatically stop running whenever the browser tab (or any session) is closed.
To create a two-file app, create a new directory (for example, newdir/ ) and place two files, called ui. R and server. R , in the directory. To run it, call runApp("newdir") .
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.
/home/username/services/volumes/shiny/apps
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)
If everything is ok you should see screenshot:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With