Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rbcavanaugh opened this issue Nov 29, 2021 · 3 comments

Comments

@rbcavanaugh
Copy link

rbcavanaugh commented Nov 29, 2021

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:

  • Shiny 1.7.1
  • testthat 3.1.0
  • shinytest 1.5.1
  • bslib 0.3.1
@wch
Copy link
Collaborator

wch commented Nov 30, 2021

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
Copy link
Author

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
Copy link
Contributor

@rbcavanaugh It should be fine while ignoring the UI changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants