rstudio / shinytest

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

recordTest()/ShinyDriver NULL navbarPage() input for bslib::bs_theme(version = 5) #424

Open rbcavanaugh opened 3 years ago

rbcavanaugh commented 3 years ago

I'm running into this issue while trying to write a test for a shiny app that uses the new bslib::bs_theme(version = 5). The following reprex appears to work perfectly fine. However, when running using shinytest::recordTest(), it returns the following:

> NULL
> Loading required package: shiny
> Running application in test mode.

This does not occur for theme = bslib::bs_theme(version = 4). Obviously, this is problematic in trying to write a test to make sure the app is on the correct page.

thanks!

library(shiny)

ui <- navbarPage(id = "mainpage",
    title = "Hello",
    theme = bslib::bs_theme(version = 5),
    tabPanel("page1")
)

server <- function(input, output, session) {

    observe({
        print(input$mainpage)
    })

}

shinyApp(ui, server)
#> 
#> Listening on http://127.0.0.1:7406
#> [1] "page1"

Created on 2021-11-29 by the reprex package (v2.0.1)

Using:

wch commented 3 years ago

Unfortunately, PhantomJS (which is what shinytest uses for a headless browser) does not work with Bootstrap 5.

We're currently working on a successor to shinytest which uses headless Chrome.

rbcavanaugh commented 3 years ago

Ah thanks so much! Makes sense. I am thinking a not-ideal but sufficient for now workaround would be something like:

theme <- function(){
  versionNumber = if (isTRUE(getOption("shiny.testmode"))) {
    4
  } else {
    5
  }
      bslib::bs_theme(bootswatch = "default",
                     base_font = bslib::font_google("Open Sans"),
                     heading_font = bslib::font_google("Open Sans"),
                     version = versionNumber,
                     `enable-rounded` = FALSE,
                     `enable-transitions` = F,
                     primary = "#1665AC"
    )
}

Do you have a sense if there would be any concerns testing app functionality using this approach? (not worrying about the UI changes from bootstrap 4 to 5)

schloerke commented 3 years ago

@rbcavanaugh It should be fine while ignoring the UI changes