Setting:
I have one Shiny-App (app.r) from which I want a reactive graph of all reactive elements. In my understanding, one must trigger these elements once before they are shown in the graph. Therefore, I created a Start_App.r which runs the app and records reactive elements and a Navigate_through_App.r-Script which navigates via RSelenium through the App. Because R is busy when running a shiny app, both scripts need to run in different R Sessions. Starting them 'by hand' results in the required reactive graph:
In order to automate the process of starting two R Sessions and executing the scripts, I created a simple Batch-file called Start.bat. It starts the shiny app, the RSelenium browser and navigates through the app as intended.
Problem: When I run the batch-script, the files recorded by the reactlog-command can't be found on my machine:
It looks like there was a try to create this file (because there is this explicit path), but somehow it does not worked. Any ideas what could cause this problem?
Code: (All files in the same folder)
app.r
library(shiny)
library(shinyjs)
jscode <- "shinyjs.closeWindow = function() { window.close(); }"
ui <- fluidPage(
useShinyjs(),
extendShinyjs(text = jscode, functions = c("closeWindow")),
actionButton("close", "Close window")
)
server <- function(input, output, session) {
observeEvent(input$close, {
js$closeWindow()
stopApp()
})
}
shinyApp(ui, server)
Start_App.r
#Install & load packages
if (!require("shiny")) install.packages("shiny")
library(shiny)
if (!require("reactlog")) install.packages("reactlog")
library(reactlog)
#tell shiny to log reactivity
#reactlog::reactlog_enable()
options(shiny.reactlog = TRUE)
#run App
runApp(getwd(), host = getOption("shiny.host", "127.0.0.1"), port=7777, launch.browser = TRUE)
#once app has closed, display reactlog from shiny
shiny::reactlogShow()
Navigate_through_App.r:
#Install & load packages
if (!require("RSelenium")) install.packages("RSelenium")
library(RSelenium)
#free all ports
system("taskkill /im java.exe /f", intern=FALSE, ignore.stdout=FALSE)
#Start Selenium and access shiny-app
rD <- rsDriver(port = 4564L, browser = "firefox") # "chrome" / "firefox" is possible
#Assign the client to an object
remDr <- rD[["client"]]
#Open Shiny-App
remDr$navigate("http://127.0.0.1:7777")
#Stop App
#Click button "App beenden & Browser schließen"
webElem <- remDr$findElement(using = 'xpath', value = '//*[@id="close"]')
webElem$clickElement()
Start.bat:
START /HIGH R -e "source('Start_App.r')"
Rscript Navigate_through_App.r
pause

