I have a shiny app which is created using a package (similar to the golem structure) and am looking to add some tests to the package.
The package contains a function run_dev
which returns a shiny.appobj
As far as I understand I can not launch the shinytest::ShinyDriver
using the app object directly as it yields
Error: path is not a string (length 1 character)
In addition: Warning message:
In if (grepl("^http(s?)://", path)) { :
the condition has length > 1 and only the first element will be used
so to get around this I am trying to run the app from a temporary directory such that I can clean up again afterwards. A minimal test might look like
driver = shinytest::ShinyDriver
temp_path = tempdir()
app_file = file.path(temp_path, "app.R")
writeLines("test_package_app::run_dev()", con = app_file)
app_runner = driver$new(temp_path)
expect_equal(app_runner$getTitle(), "test")
But when the app.R file lives in a temporary directory I get the following
Error in sd_startShiny(self, private, path, seed, loadTimeout, shinyOptions) :
Error starting application:
Running application in test mode.
Loading required package: shiny
Error : No root directory found in /tmp/RtmpU3lMUs or its parent directories. Root criterion: contains a file `DESCRIPTION`
If I pass the path to the app file instead of the directory that contains it I get
Error in is_rmd(path) :
Unknown whether app is a regular Shiny app or .Rmd: /tmp/RtmpU3lMUs/app.R
Further investigation shows that if I try to run the app from this directory at all I hit similar errors
shiny::shinyAppDir(temp_path)
Error: No root directory found in /tmp/RtmpU3lMUs or its parent directories. Root criterion: contains a file `DESCRIPTION`
shinyAppFile(app_file)
Error: No root directory found in /tmp/RtmpU3lMUs or its parent directories. Root criterion: contains a file `DESCRIPTION`
Does anyone know what is causing this?
Version info:
shinytest_1.3.1
shiny_1.4.0
R 3.6.2
Ubuntu 18.04.4 LTS
Edit:
To add, if I have the app file in the package root this does work OK