rstudio / bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
https://rstudio.github.io/bslib/
Other
486 stars 58 forks source link

Updating from bslib 0.2.5.1 to 0.3.1 changes app behavior #387

Closed rbcavanaugh closed 3 years ago

rbcavanaugh commented 3 years ago

I apologize for the lack of a helpful reprex on this issue...I can't seem to reproduce this issue with a minimal example.

I have a shiny app that nests tabsetpanels within navbarpages. I originally themed the app using bslib 0.2.5.1 (fantastic, thank you!) using bootstrap 4. However, I recently updated bslib to 0.3.1, and now theupdateNavbarPage() function (triggered by an action button) does not seem to be working when bs_theme() is set to bootstrap4. Changing to bootstrap 3 and bootstrap 5 both resolve the issue, but I'd like to use bootstrap 4 as bs3 is a little outdated and bs5 doesn't yet work with shinyWidgets.

Is there any reason the bslib update would break the updateNavbarPage() function?

I also tried to roll back to 0.2.5.1 but I'm getting the error: "Warning: Error in : 'page_navbar' is not an exported object from 'namespace:bslib'" so I'm a little stuck.

Thank you, Rob

A (working) reprex of the app structure. In my app, actionButton("go_to_nav2") does not do anything with bslib 0.3.1 and bs4, but works for bs3 and bs5.

library(shiny)
library(bslib)
#> 
#> Attaching package: 'bslib'
#> The following object is masked from 'package:utils':
#> 
#>     page

ui <- navbarPage(
  title = "Shiny App Reprex Bslib",
  id = "navs",
  theme = bslib::bs_theme(
    bootswatch = "default",
    base_font = bslib::font_google("Open Sans"),
    heading_font = bslib::font_google("Open Sans"),
    version = "4",
    `enable-rounded` = T,
    `enable-transitions` = F,
    primary = "#1665AC",
    "navbar-bg" = "#dee2e6"
  ),

  tabPanel(value = "nav_panel1", title = "Page 1", 
               tabsetPanel(
                 type = "hidden",
                 id = "tabs",
                 tabPanelBody(value = "tab1",
                              h2("tab 1"),
                              actionButton("go_to_tab2", "Tab 1")
                 ),
                 tabPanelBody(value = "tab2",
                              h2("tab 2"),
                              actionButton("go_to_tab3", "Tab 2")
                 ),
                 tabPanelBody(value = "tab3",
                              h2("tab 3"),
                              actionButton("go_to_nav2", "Tab 3")
                 )
               )
           ),
  tabPanel(value = "nav_panel2", title = "Page 2",
           h2("Page 2")

          )
)

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

  observeEvent(input$go_to_tab2,{
    updateTabsetPanel(session, "tabs", selected = "tab2")
  })

  observeEvent(input$go_to_tab3,{
    updateTabsetPanel(session, "tabs", selected = "tab3")
  })

  observeEvent(input$go_to_nav2,{
    updateTabsetPanel(session, "navs", selected = "nav_panel2")
  })
}

shinyApp(ui = ui, server = server)

Created on 2021-10-21 by the reprex package (v2.0.1)

cpsievert commented 3 years ago

I think there is a fix for this in the development version? remotes::install_github("rstudio/bslib")

cpsievert commented 3 years ago

Confirmed that this works with development version. Please reopen if I'm missing something

rbcavanaugh commented 3 years ago

Thank you. Upgraded to the dev version and downgrading to shiny 1.6 seems to have solved the issue. (previously using shiny 1.7.1).

cpsievert commented 3 years ago

Huh, strange. I actually seem to get the right behavior with the CRAN version of both bslib (0.3.1) and shiny (1.7.1). Would you mind including your sessioninfo::session_info() as well as a screen-recording of the incorrect behavior?

rbcavanaugh commented 3 years ago

Sure - Please let me know if the recording isn't exactly what you're referrring to.

https://user-images.githubusercontent.com/46727239/138347504-9d5e7066-7d50-42f2-b0f6-b88905bcd08b.mov

(The only difference to session info before/after is shiny [1] shiny_1.6.0 vs. [1] shiny_1.7.1)

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS  11.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.7.1            mainConcept_0.0.1.0000

loaded via a namespace (and not attached):
 [1] fs_1.5.0            usethis_2.0.1       shinipsum_0.1.0    
 [4] fontawesome_0.2.2   webshot_0.5.2       httr_1.4.2         
 [7] rprojroot_2.0.2     tools_4.0.3         bslib_0.3.1.9000   
[10] utf8_1.2.2          R6_2.5.1            DT_0.18            
[13] DBI_1.1.1           lazyeval_0.2.2      colorspace_2.0-2   
[16] withr_2.4.2         tidyselect_1.1.1    compiler_4.0.3     
[19] waiter_0.2.4.9000   cli_3.0.1.9000      rvest_1.0.1        
[22] xml2_1.3.2          shinyjs_2.0.0       desc_1.3.0         
[25] plotly_4.9.4.1      sass_0.4.0.9000     scales_1.1.1       
[28] dygraphs_1.1.1.6    readr_2.0.0         systemfonts_1.0.2  
[31] stringr_1.4.0       digest_0.6.28       rmarkdown_2.10     
[34] svglite_2.0.0       pkgconfig_2.0.3     htmltools_0.5.2    
[37] attempt_0.3.1       fastmap_1.1.0       htmlwidgets_1.5.3  
[40] rlang_0.99.0.9000   rstudioapi_0.13     jquerylib_0.1.4    
[43] generics_0.1.0      zoo_1.8-9           jsonlite_1.7.2     
[46] dplyr_1.0.7         config_0.3.1        googlesheets4_1.0.0
[49] magrittr_2.0.1      kableExtra_1.3.4    Rcpp_1.0.7         
[52] munsell_0.5.0       fansi_0.5.0         lifecycle_1.0.1    
[55] stringi_1.7.3       yaml_2.2.1          grid_4.0.3         
[58] promises_1.2.0.1    crayon_1.4.1        lattice_0.20-44    
[61] cowplot_1.1.1       hms_1.1.0           knitr_1.33         
[64] pillar_1.6.2        markdown_1.1        pkgload_1.2.1      
[67] glue_1.4.2          evaluate_0.14       golem_0.3.1        
[70] data.table_1.14.0   remotes_2.4.0       vctrs_0.3.8        
[73] tzdb_0.1.2          httpuv_1.6.3        testthat_3.1.0     
[76] cellranger_1.1.0    gtable_0.3.0        purrr_0.3.4        
[79] tidyr_1.1.3         assertthat_0.2.1    cachem_1.0.6       
[82] ggplot2_3.3.5       xfun_0.25           mime_0.12          
[85] xtable_1.8-4        roxygen2_7.1.1      later_1.3.0        
[88] googledrive_2.0.0   viridisLite_0.4.0   gargle_1.2.0       
[91] dockerfiler_0.1.3   tibble_3.1.3        shinyWidgets_0.6.2 
[94] ellipsis_0.3.2      here_1.0.1    
cpsievert commented 3 years ago

And just to make sure, you can reproduce that behavior with your minimal example (for some reason it seems I'm unable to)?

It'd also be helpful if you could relay any JS console errors by doing right-click -> Inspect -> Console after clicking in the button that triggers a call to updateTabsetPanel()

cpsievert commented 3 years ago

Also I can see warnings in your R console that might be related to the issue. Those warnings are letting you know that you're passing something other than tabPanel()s/navbarMenu()s to a tabsetPanel()/navbarPage(), which leads to undefined behavior. It might be worth seeing if fixing those warnings will fix the issue.

rbcavanaugh commented 3 years ago

No sorry - the reprex seems to work fine, I was just trying to show the app structure. The recording shows it not working with the full app. Those warnings in the R console are just from a few br() at the bottom of navbarPage() that I need to include in the footer instead; removing them doesn't fix the issue.

The only console message is below, but it is present as soon as the app loads, not triggered by the button.

[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

I'm ok downgrading to shiny 1.6 for now and slowly building up the reprex to figure out what breaks it as I'm able to.thanks for your help!

cpsievert commented 3 years ago

OK if you're not seeing any JavaScript errors, I suspect something might be wrong the id/value matching in the tabPanel()/updateTabsetPanel()

rbcavanaugh commented 3 years ago

thanks - thats what I thought too but the id/value are the same regardless of whether version = "4" or version = "5" in bslib::be_theme(). I checked using inspect as well and the values don't seem to change.

xsvato01 commented 2 years ago

Had the same problem, thank you @rbcavanaugh for the heads up!

github-actions[bot] commented 1 year ago

This issue has been automatically locked. If you believe you have found a related problem, please open a new issue (with a reproducible example or feature request) and link to this issue.