rstudio / shinytest2

https://rstudio.github.io/shinytest2/
Other
106 stars 18 forks source link

app$expect_values( ) Error in `app_httr_get()` Could not find Shiny server. Shiny app is no longer running #242

Open feddelegrand7 opened 2 years ago

feddelegrand7 commented 2 years ago

Hi, Thank you for the amazing package, I'm encountering a strange error. When I record a test app, I click on Expect Shiny Values, works great but then when I hit Save test and exit, I get the following Error:

Error in `app_httr_get()` at shinytest2/R/app-driver-expect-values.R:171:2:
! Could not find Shiny server. Shiny app is no longer running

I tried to reproduce the test in code (see below please), I get the same error.

testthat::test_that("testing table outputs in dt_editable module", {

  app <- shinytest2::AppDriver$new(
    app_dir = file_path,
    variant = shinytest2::platform_variant(), 
    name = "dt_editable_dev"
  )

 # The following works fine
  app$wait_for_idle(duration = 1000)
  mpg_table <- app$get_html("#mpg_data-editable_dt")
  mtcars_table <- app$get_html("#mtcars_data-editable_dt")
  first_row_in_app <- app$get_text(
    selector = "#mtcars_data-editable_dt tr:first-child td"
  ) 

 # The error comes from this line of code
 app$expect_values(output = "mpg_data-editable_dt")
})

When I try to view( ) the app, I get the following error: 

Fontconfig warning: "/etc/fonts/fonts.conf", line 86: unknown element "blank" [11926:11926:0726/155925.132116:ERROR:ozone_platform_x11.cc(247)] Missing X server or $DISPLAY [11926:11926:0726/155925.132160:ERROR:env.cc(226)] The platform failed to initialize. Exiting.

Maybe it's related the error in the subject but then why the get_url( ) works well :/

Thanks again for the great work :) 

─ Session info ───────────────────────────────────
 setting  value
 version  R version 3.6.0 (2019-04-26)
 os       CentOS Linux 7 (Core)
 system   x86_64, linux-gnu
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Berlin
 date     2022-07-26
 rstudio  2022.02.1+461.pro1 Prairie Trillium (server)
 pandoc   NA
DivadNojnarg commented 2 years ago

Hi @feddelegrand7 ,

Not sure but from your session you are running RStudio server and I don't think we can call $view from there. This might help you, where I do port forwarding through ssh.

feddelegrand7 commented 2 years ago

Hi @DivadNojnarg yes I'm working on RStudio Server, the issue is that when trying to use "expect_values" to test reactive objects in my Shiny app (without trying to call View() ), I get an error. I'll take a look at the workaround, thank you so much for your help

clabornd commented 2 years ago

I am having a similar error when running tests in Gitlab CI on a kubernetes runner. The two commands that I have tried that error are app$get_value:

Error in `app_httr_get(self, private, url, fn_404 = function(req) {
    app_abort(self, private, c(paste0("Shiny server returned 404 for values URL: ", 
        url), i = "Is `shiny::runApp(test.mode = TRUE)` enabled?"), 
        call = cur_env)
})`: Could not find Shiny server. Shiny app is no longer running
Backtrace:
 1. base::print(app$get_value(input = "transform"))
      at test_peptide_workflow.R:32:2
 2. app$get_value(input = "transform")
 3. shinytest2:::app_get_value(...)
 4. self$get_values(...)
 5. shinytest2:::app_get_values(...)
 6. shinytest2:::app_httr_get(...)

and app$wait_for_value

Error in `app_wait_for_value(self, private, input = input, output = output, 
    export = export, ..., ignore = ignore, timeout = timeout, 
    interval = interval)`: timeout reached when waiting for input: datatype
Backtrace:
 1. app$wait_for_value(input = "datatype")
      at test_peptide_workflow.R:16:2
 2. shinytest2:::app_wait_for_value(...)

The tests pass running locally inside the same container specified in .gitlab-ci.yml. Looking at screenshots, the app navigation works fine, and the input that is passed to wait_for_value and get_value are at least rendered on screen when the methods are called.