rstudio / shinytest

Automated testing for shiny apps
https://rstudio.github.io/shinytest/
Other
225 stars 55 forks source link

Cannot find shiny port number with a global.R file #111

Closed KZARCA closed 6 years ago

KZARCA commented 7 years ago

Hi, I found a strange behaviour with shinytest. When I run recordTest(), I get an error: Error in sd_startShiny(self, private, path) : Cannot find shiny port number. Error: Running application in test mode. I don't know how related this issue is to #99 and #104. It seems due to the presence of a global.R file and package loading. When I load packages in server.R and/or ui.R, I do not get this problem.

My minimal reproductible example is this one:

ui.R

  fluidPage()

server.R

shinyServer(function(input, output, session) {
})

global.R

library(shinyjs)
library(RCurl)
library(Hmisc)
library(boot)
library(car)
library(cowplot)
library(dplyr)
library(purrr)
library(shinydashboard)

Session info

Session info ----------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.0 (2017-04-21)
 system   x86_64, linux-gnu           
 ui       RStudio (1.0.143)           
 language fr_FR:en                    
 collate  fr_FR.UTF-8                 
 tz       Europe/Paris                
 date     2017-06-21                  

Packages --------------------------------------------------------------------------------------------------------
 package   * version date       source        
 package        * version    date       source                                
 acepack          1.4.1      2016-10-29 CRAN (R 3.4.0)                        
 assertthat       0.2.0      2017-04-11 CRAN (R 3.4.0)                        
 backports        1.1.0      2017-05-22 CRAN (R 3.4.0)                        
 base           * 3.4.0      2017-04-21 local                                 
 base64enc        0.1-3      2015-07-28 CRAN (R 3.4.0)                        
 bitops         * 1.0-6      2013-08-17 CRAN (R 3.4.0)                        
 boot           * 1.3-19     2017-04-21 CRAN (R 3.4.0)                        
 car            * 2.1-4      2016-12-02 CRAN (R 3.4.0)                        
 checkmate        1.8.2      2016-11-02 CRAN (R 3.4.0)                        
 cluster          2.0.6      2017-03-16 CRAN (R 3.4.0)                        
 colorspace       1.3-2      2016-12-14 CRAN (R 3.4.0)                        
 compiler         3.4.0      2017-04-21 local                                 
 cowplot        * 0.7.0      2016-10-28 CRAN (R 3.4.0)                        
 crayon           1.3.2      2016-06-28 CRAN (R 3.4.0)                        
 curl             2.6        2017-04-27 CRAN (R 3.4.0)                        
 data.table       1.10.4     2017-02-01 CRAN (R 3.4.0)                        
 datasets       * 3.4.0      2017-04-21 local                                 
 debugme          1.0.2      2017-06-20 Github (gaborcsardi/debugme@df8295a)  
 devtools         1.13.2     2017-06-02 CRAN (R 3.4.0)                        
 digest           0.6.12     2017-01-27 CRAN (R 3.4.0)                        
 dplyr          * 0.7.0      2017-06-09 CRAN (R 3.4.0)                        
 foreign          0.8-68     2017-04-24 CRAN (R 3.4.0)                        
 Formula        * 1.2-1      2015-04-07 CRAN (R 3.4.0)                        
 ggplot2        * 2.2.1      2016-12-30 CRAN (R 3.4.0)                        
 glue             1.1.0      2017-06-13 CRAN (R 3.4.0)                        
 graphics       * 3.4.0      2017-04-21 local                                 
 grDevices      * 3.4.0      2017-04-21 local                                 
 grid             3.4.0      2017-04-21 local                                 
 gridExtra        2.2.1      2016-02-29 CRAN (R 3.4.0)                        
 gtable           0.2.0      2016-02-26 CRAN (R 3.4.0)                        
 Hmisc          * 4.0-2      2016-12-31 CRAN (R 3.4.0)                        
 htmlTable        1.9        2017-01-26 CRAN (R 3.4.0)                        
 htmltools        0.3.6      2017-04-28 CRAN (R 3.4.0)                        
 htmlwidgets      0.8        2016-11-09 CRAN (R 3.4.0)                        
 httpuv           1.3.3      2015-08-04 CRAN (R 3.4.0)                        
 httr             1.2.1      2016-07-03 CRAN (R 3.4.0)                        
 jsonlite         1.5        2017-06-01 CRAN (R 3.4.0)                        
 knitr            1.16       2017-05-18 CRAN (R 3.4.0)                        
 lattice        * 0.20-35    2017-03-25 CRAN (R 3.4.0)                        
 latticeExtra     0.6-28     2016-02-09 CRAN (R 3.4.0)                        
 lazyeval         0.2.0      2016-06-12 CRAN (R 3.4.0)                        
 lme4             1.1-13     2017-04-19 CRAN (R 3.4.0)                        
 magrittr         1.5        2014-11-22 CRAN (R 3.4.0)                        
 MASS             7.3-47     2017-04-21 CRAN (R 3.4.0)                        
 Matrix           1.2-10     2017-04-28 CRAN (R 3.4.0)                        
 MatrixModels     0.4-1      2015-08-22 CRAN (R 3.4.0)                        
 memoise          1.1.0      2017-04-21 CRAN (R 3.4.0)                        
 methods        * 3.4.0      2017-04-21 local                                 
 mgcv             1.8-17     2017-02-08 CRAN (R 3.4.0)                        
 mime             0.5        2016-07-07 CRAN (R 3.4.0)                        
 miniUI           0.1.1      2016-01-15 CRAN (R 3.4.0)                        
 minqa            1.2.4      2014-10-09 CRAN (R 3.4.0)                        
 munsell          0.4.3      2016-02-13 CRAN (R 3.4.0)                        
 nlme             3.1-131    2017-02-06 CRAN (R 3.4.0)                        
 nloptr           1.0.4      2014-08-04 CRAN (R 3.4.0)                        
 nnet             7.3-12     2016-02-02 CRAN (R 3.4.0)                        
 parallel         3.4.0      2017-04-21 local                                 
 parsedate        1.1.3      2017-03-02 CRAN (R 3.4.0)                        
 pbkrtest         0.4-7      2017-03-15 CRAN (R 3.4.0)                        
 pingr            1.1.2      2017-03-02 CRAN (R 3.4.0)                        
 plyr             1.8.4      2016-06-08 CRAN (R 3.4.0)                        
 png              0.1-7      2013-12-03 CRAN (R 3.4.0)                        
 processx         2.0.1      2017-06-20 Github (MangoTheCat/processx@4bf780f) 
 purrr          * 0.2.2      2016-06-18 CRAN (R 3.4.0)                        
 quantreg         5.33       2017-04-18 CRAN (R 3.4.0)                        
 R6               2.2.2      2017-06-17 CRAN (R 3.4.0)                        
 RColorBrewer     1.1-2      2014-12-07 CRAN (R 3.4.0)                        
 Rcpp             0.12.11    2017-05-22 CRAN (R 3.4.0)                        
 RCurl          * 1.95-4.8   2016-03-01 CRAN (R 3.4.0)                        
 rematch          1.0.1      2016-04-21 CRAN (R 3.4.0)                        
 rlang            0.1.1      2017-05-18 CRAN (R 3.4.0)                        
 rpart            4.1-11     2017-04-21 CRAN (R 3.4.0)                        
 rstudioapi       0.6        2016-06-27 CRAN (R 3.4.0)                        
 scales           0.4.1      2016-11-09 CRAN (R 3.4.0)                        
 shiny          * 1.0.3      2017-04-26 CRAN (R 3.4.0)                        
 shinydashboard * 0.6.0      2017-05-18 CRAN (R 3.4.0)                        
 shinyjs        * 0.9        2016-12-26 CRAN (R 3.4.0)                        
 shinytest      * 1.0.2      2017-06-20 Github (rstudio/shinytest@364c97b)    
 showimage        1.0.0      2017-06-20 Github (MangoTheCat/showimage@d9000f0)
 SparseM          1.77       2017-04-23 CRAN (R 3.4.0)                        
 splines          3.4.0      2017-04-21 local                                 
 stats          * 3.4.0      2017-04-21 local                                 
 stringi          1.1.5      2017-04-07 CRAN (R 3.4.0)                        
 stringr          1.2.0      2017-02-18 CRAN (R 3.4.0)                        
 survival       * 2.41-3     2017-04-04 CRAN (R 3.4.0)                        
 testthat         1.0.2      2016-04-23 CRAN (R 3.4.0)                        
 tibble           1.3.3      2017-05-28 CRAN (R 3.4.0)                        
 tools            3.4.0      2017-04-21 local                                 
 utils          * 3.4.0      2017-04-21 local                                 
 webdriver        1.0.2.9000 2017-06-20 Github (rstudio/webdriver@4ac393a)    
 withr            1.0.2      2016-06-20 CRAN (R 3.4.0)                        
 xtable           1.8-2      2016-02-05 CRAN (R 3.4.0)
wch commented 7 years ago

Interesting, I think it's because when those calls are in global.R, it prints out a lot of package loading messages before the Listening on http://127.0.0.1:7738.

Can you try doing this and see if it makes a difference?

suppressPackageStartupMessages({
  library(shinyjs)
  library(RCurl) #base64
  library(Hmisc)
  library(boot)
  library(car)
  library(cowplot)
  library(dplyr)
  library(purrr)
  library(shinydashboard)
})
wch commented 7 years ago

Actually, I think now that the problem is that the packages take a long time to load, and it's timing out while waiting for the app to start. The reason that it's different between global.R and server.R is that that global.R is sourced before it prints out Listening on http://127.0.0.1:7738, and server.R is sourced after.

KZARCA commented 7 years ago

Thanks a lot! With suppressPackageStartupMessages(), it works perfectly.

ghost commented 6 years ago

I have a similar issue using global.R. My time lag is caused by loading data using the googlesheets package in the global.R. Can we look to create a parameter in recordTest() to increase the wait time to check for a shiny port?

scarfaace commented 6 years ago

@KZARCA Please, can you explain me how you fixed it? I am having the same issue. When I run recordTest() on a really small app, it works without any problems. If I run recordTest() on my really big application, I am getting the same error. I do not understand how you use suppressPackageStartupMessages() and how is it possible that it fixed the problem.

wch commented 6 years ago

I've added a loadTimeout parameter to recordTest() in 89a0c09.

@alik33 If you have a chance, please try it out and let us know if it works for you.

scarfaace commented 6 years ago

@wch I tried it, set loadTimeout to 100000 and it did not work. So I rewrote loadTimeout's default value from 10000 to 100000, installed that and it works now.

wch commented 6 years ago

@alik33 Are you saying that it didn't work to do recordTest(..., loadTimeout=100000), but it did work to change the function signature of recordTest() so that the default value for loadTimeout was 100000?

scarfaace commented 6 years ago

@wch Exactly, completely weird.

wch commented 6 years ago

@alik33 Very strange. I have no idea why that would make a difference.

cderv commented 5 years ago

I just had the issue during Shiny in producton workshop at RStudio Conf, and I can confirm the loadTimeout argument work. I use recordTest(..., loadTimeout=100000) and no more error about shiny port.

deanlie commented 2 years ago

I had already recorded a longish test and wanted to use it. My app loads & processes a lot of data before starting the UI.

"testApp("", loadTimeout=100000)" gave an "unused argument" error, but when I put "loadTimeout=100000" right in the first line of the test, i.e. the first line of mytest.R is

app <- ShinyDriver$new("../../", loadTimeout=100000)

it works. Thanks all!

bersbersbers commented 2 years ago

ShinyDriver$new("../../", loadTimeout=100000) also helps avoiding "Cannot find shiny port number" when using gctorture2(999, inhibit_release = TRUE)