servr
servr copied to clipboard
Daemon mode breaks RSelenium's navigate() method
For animint, we've been using servr and RSelenium to test whether plots are rendered in the browser the way we expect. Plot rendering requires a file server, so before I discovered the new daemon support, I did something like:
library(servr)
library(RSelenium)
cmd <- "R -e \'cat(Sys.getpid(), file=\"pid.txt\"); servr::httd(dir=system.file(\"examples/make1\", package=\"servr\"), port=4848, browser=FALSE)\'"
system(cmd, wait = FALSE)
# start selenium server, open firefox, and navigate to file server on localhost
checkForServer(dir=system.file("bin", package = "RSelenium"))
startServer()
remDr <- remoteDriver(browserName = "firefox")
remDr$open(silent = TRUE)
remDr$navigate("http://localhost:4848/")
# kill the file server
tools::pskill(readLines("pid.txt", warn = F))
However, I run into problems if I use daemon=TRUE
res <- httd(dir = system.file("examples/make1", package = "servr"),
daemon = TRUE, port = 4848, browser = FALSE)
# The line below freezes firefox & the R session. However, it works if I _manually_ navigate there
# I can also use other methods like `remDr$getPageSource()`
remDr$navigate("http://localhost:4848/")
Any ideas why the daemon approach might cause this problem? Is there a somewhat simple explanation of the difference between the two approaches? Maybe @johndharrison could help? I don't think it's a browser issue as I've also tested this with phantomjs.
I'm in China this month, and I'm behind the Great Fire Wall. It's inconvenient for me to download Selenium, so I have no idea here.
No worries. I can always go with the first approach. Enjoy China!
This seems to be an issue when RStudio is used as an IDE. Using the RGui or command line R I don't seem to encounter this issue.
library(RSelenium)
library(servr)
remDr <- remoteDriver(browserName = "chrome")
remDr$open(silent = TRUE)
res <- httd(dir = system.file("examples/make1", package = "servr"),
daemon = TRUE, port = 4848, browser = FALSE)
remDr$navigate("http://localhost:4848/")
The navigate method completes for me in the background what I observe is RStudio "R Session Aborted".