How to test that a shiny app is deployed using testthat?

44 views
Skip to first unread message

Leonardo Collado Torres

unread,
Jul 13, 2016, 4:10:59 PM7/13/16
to ShinyApps Users
Hi,

How would you test that a shiny app is deployed? I thought of using Rcurl::url.exists() which works if the app is runnin, but not if it's sleeping. For example:

> library(testthat)
>         expect_equal(
+             RCurl::url.exists('https://jhubiostatistics.shinyapps.io/recount/'),
+             TRUE
+         )
Error: RCurl::url.exists("https://jhubiostatistics.shinyapps.io/recount/") not equal to TRUE.
1 element mismatch
> options(width = 120)
> devtools::session_info()
Session info -----------------------------------------------------------------------------------------------------------
 setting  value                                 
 version  R version 3.3.0 RC (2016-05-01 r70572)
 system   x86_64, darwin13.4.0                  
 ui       AQUA                                  
 language (EN)                                  
 collate  en_US.UTF-8                           
 tz       America/New_York                      
 date     2016-07-13                            

Packages ---------------------------------------------------------------------------------------------------------------
 package  * version  date       source        
 bitops     1.0-6    2013-08-17 CRAN (R 3.3.0)
 crayon     1.3.2    2016-06-28 CRAN (R 3.3.0)
 devtools   1.12.0   2016-06-24 CRAN (R 3.3.0)
 digest     0.6.9    2016-01-08 CRAN (R 3.3.0)
 magrittr   1.5      2014-11-22 CRAN (R 3.3.0)
 memoise    1.0.0    2016-01-29 CRAN (R 3.3.0)
 R6         2.1.2    2016-01-26 CRAN (R 3.3.0)
 RCurl      1.95-4.8 2016-03-01 CRAN (R 3.3.0)
 testthat * 1.0.2    2016-04-23 CRAN (R 3.3.0)
 withr      1.0.2    2016-06-20 CRAN (R 3.3.0)



Interactively, I can force the app to be running by using utils::browseURL() first, but that won't work when testing in a non-interactive environment. Such as with:

if(interactive()) {
    ## Open shiny app when running test in interactive mode.
    ## This will force the app to be available, which will then run the test
    ## successfully.
    test_that('Shiny app is up', {
        expect_equal(
            RCurl::url.exists('https://jhubiostatistics.shinyapps.io/recount/'),
            TRUE
        )
    })
}


Thank you!
Leo



Tareef Kawaf

unread,
Jul 14, 2016, 7:36:32 AM7/14/16
to Leonardo Collado Torres, ShinyApps Users
Yes, unfortunately you would need to use a tool like phantomjs to hit your application and start it up.  Recall that applications are put to sleep when they aren't receiving traffic, unless you specifically tune them to stay up for a longer period of time.

--
You received this message because you are subscribed to the Google Groups "ShinyApps Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shinyapps-users/ad1ab6ae-351d-4c0e-be1c-135dfecea2d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonardo Collado Torres

unread,
Jul 14, 2016, 11:37:11 AM7/14/16
to ShinyApps Users, fellg...@gmail.com
Ok, thank you for the info!

Best,
Leo
Reply all
Reply to author
Forward
0 new messages