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

navbarMenu() aren't being selected properly on pageload #3519

Closed
nuno-agostinho opened this issue Oct 1, 2021 · 4 comments · Fixed by rstudio/bslib#372
Closed

navbarMenu() aren't being selected properly on pageload #3519

nuno-agostinho opened this issue Oct 1, 2021 · 4 comments · Fixed by rstudio/bslib#372
Assignees
Labels
Type: Regression Functionality from a previous release no longer works

Comments

@nuno-agostinho
Copy link
Contributor

nuno-agostinho commented Oct 1, 2021

System details

Browser Version: Safari 15.0

Output of sessionInfo():

R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] cTRAP_1.10.2   purrr_0.3.4    shiny_1.7.0    testthat_3.0.4

loaded via a namespace (and not attached):
  [1] readxl_1.3.1                  backports_1.2.1               AnnotationHub_3.0.1          
  [4] fastmatch_1.1-3               BiocFileCache_2.0.0           plyr_1.8.6                   
  [7] igraph_1.2.6                  BiocParallel_1.26.2           crosstalk_1.1.1              
 [10] usethis_2.0.1                 GenomeInfoDb_1.28.4           ggplot2_3.3.5.9000           
 [13] digest_0.6.28                 highcharter_0.8.2             htmltools_0.5.2              
 [16] fansi_0.5.0                   magrittr_2.0.1                memoise_2.0.0                
 [19] limma_3.48.3                  remotes_2.4.1                 Biostrings_2.60.2            
 [22] R.utils_2.11.0                xts_0.12.1                    prettyunits_1.1.1            
 [25] colorspace_2.0-2              blob_1.2.2                    rappdirs_0.3.3               
 [28] ggrepel_0.9.1                 xfun_0.26                     dplyr_1.0.7                  
 [31] callr_3.7.0                   crayon_1.4.1                  RCurl_1.98-1.5               
 [34] jsonlite_1.7.2                roxygen2_7.1.2                zoo_1.8-9                    
 [37] glue_1.4.2                    gtable_0.3.0                  zlibbioc_1.38.0              
 [40] XVector_0.32.0                pkgbuild_1.2.0                Rhdf5lib_1.14.2              
 [43] BiocGenerics_0.38.0           quantmod_0.4.18               scales_1.1.1                 
 [46] DBI_1.1.1                     Rcpp_1.0.7                    xtable_1.8-4                 
 [49] bit_4.0.4                     stats4_4.1.0                  DT_0.19                      
 [52] htmlwidgets_1.5.4             httr_1.4.2                    fgsea_1.18.0                 
 [55] ellipsis_0.3.2                pkgconfig_2.0.3               R.methodsS3_1.8.1            
 [58] sass_0.4.0                    dbplyr_2.1.1                  utf8_1.2.2                   
 [61] tidyselect_1.1.1              rlang_0.4.11                  reshape2_1.4.4               
 [64] later_1.3.0                   AnnotationDbi_1.54.1          munsell_0.5.0                
 [67] BiocVersion_3.13.1            cellranger_1.1.0              tools_4.1.0                  
 [70] cachem_1.0.6                  cli_3.0.1                     generics_0.1.0               
 [73] RSQLite_2.2.8                 devtools_2.4.2                broom_0.7.9                  
 [76] stringr_1.4.0                 fastmap_1.1.0                 yaml_2.2.1                   
 [79] processx_3.5.2                knitr_1.35                    bit64_4.0.5                  
 [82] fs_1.5.0                      shinycssloaders_1.0.0         KEGGREST_1.32.0              
 [85] pbapply_1.5-0                 mime_0.12                     R.oo_1.24.0                  
 [88] xml2_1.3.2                    compiler_4.1.0                rstudioapi_0.13              
 [91] filelock_1.0.2                curl_4.3.2                    png_0.1-7                    
 [94] interactiveDisplayBase_1.30.0 binr_1.1                      tibble_3.1.4                 
 [97] bslib_0.3.0                   stringi_1.7.4                 ps_1.6.0                     
[100] desc_1.4.0                    lattice_0.20-44               Matrix_1.3-4                 
[103] vctrs_0.3.8                   pillar_1.6.3                  lifecycle_1.0.1              
[106] rhdf5filters_1.4.0            BiocManager_1.30.16           jquerylib_0.1.4              
[109] data.table_1.14.2             cowplot_1.1.1                 bitops_1.0-7                 
[112] httpuv_1.6.3                  R6_2.5.1                      promises_1.2.0.1             
[115] gridExtra_2.3                 IRanges_2.26.0                sessioninfo_1.1.1            
[118] assertthat_0.2.1              pkgload_1.2.2                 fontawesome_0.2.2            
[121] rhdf5_2.36.0                  rprojroot_2.0.2               withr_2.4.2                  
[124] S4Vectors_0.30.0              GenomeInfoDbData_1.2.6        rlist_0.4.6.2                
[127] parallel_4.1.0                grid_4.1.0                    tidyr_1.1.4                  
[130] Cairo_1.5-12.2                TTR_0.24.2                    Biobase_2.52.0               
[133] lubridate_1.7.10

Example application or steps to reproduce the problem

ui <- navbarPage(
    "my app",
    id="tab",
    navbarMenu("Load", icon=icon("table"),
               tabPanel("Custom Data", "custom data: please upload"),
               "----",
               tabPanel("Public Data", "public data online")),
    navbarMenu("Analyse", icon=icon("cogs"),
               tabPanel("quick analysis", "fast!"),
               tabPanel("slow analysis", "more time")),
    navbarMenu("Visualise", icon=icon("chart-bar"),
               tabPanel("plots", "avoid pie charts")))
server <- function(input, output) {
    observe(print(input$tab))
}
shinyApp(ui=ui, server=server)

Describe the problem in detail

The current implementation of tabs with navbarPage is giving some bugs as you can see from the reproducible example.

  1. When opening the app, click in any tab inside the navigation bar. It opens as expected, but the first tab (Custom Data) is still active (blue). When trying to select the first tab (Custom Data), nothing happens.

  2. This bug is reflected by the ID of the selected tab that doesn't show correctly. When selecting a second tab, it shows the selected tab is NULL.

After clicking in some tabs, the tabs start working as expected again. I don't understand what is going on, any temporary workaround is appreciated. Thanks!

@nuno-agostinho
Copy link
Contributor Author

Just to add: this bug does not occur if the first tab is not within a dropdown menu:

ui <- navbarPage(
    "my app",
    id="tab",
    tabPanel("Custom Data", "custom data: please upload"),
    navbarMenu("Load", icon=icon("table"),
               "----",
               tabPanel("Public Data", "public data online")),
    navbarMenu("Analyse", icon=icon("cogs"),
               tabPanel("quick analysis", "fast!"),
               tabPanel("slow analysis", "more time")),
    navbarMenu("Visualise", icon=icon("chart-bar"),
               tabPanel("plots", "avoid pie charts")))
server <- function(input, output) {
    observe(print(input$tab))
}
shinyApp(ui=ui, server=server)

@cpsievert cpsievert changed the title Tabs in navbarPage working incorrectly navbarMenu() aren't being selected properly on pageload Oct 1, 2021
@cpsievert cpsievert added the Type: Regression Functionality from a previous release no longer works label Oct 1, 2021
@cpsievert cpsievert self-assigned this Oct 1, 2021
@cpsievert
Copy link
Collaborator

cpsievert commented Oct 1, 2021

Thanks for the report! The fix for this will come via the {bslib} package, which will hopefully see a CRAN release in the next week or so, but for now can do remotes::install_github("rstudio/bslib")

@nuno-agostinho
Copy link
Contributor Author

Wow, I was not expecting such a quick reply (with the issue fixed) so soon... Great job, thank you for your work! 😄

@cpsievert
Copy link
Collaborator

The fix for this is now on CRAN -- install.packages("bslib")

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue May 5, 2022
# bslib 0.3.1

## New features

* Upgraded Bootstrap 5 (i.e., `bs_theme(version = 5)`) from 5.0.2 to
  5.1.0 (#365)

## Bug fixes

* Closed rstudio/shiny#3519: `nav_menu()` (i.e.,
  `shiny::navbarMenu()`) wasn't producing an `.active` class on it's
  `.dropdown` container properly. (#372)

# bslib 0.3.0

## Breaking changes

* Closed rstudio/rmarkdown#2154: `{magrittr}`'s pipe operator (`%>%`)
  is no longer re-exported by `{bslib}`. Either `library(magrittr)` to
  make `%>%` available and/or use use R 4.1's pipe operator (`|>`).

## New features

* Closed #82: Added support for Bootstrap 5 (via `bs_theme(version =
  5)`). Bootstrap 4 remains the default in this release, but the next
  release, the default will likely change to Bootstrap 5.

## Bug fixes

* Closed #6: rmarkdown's .tabset-fade class now works with Bootstrap
  4+ since legacy use of .nav .fade is now officially supported in
  Bootstrap 4+. (#325)
cpsievert added a commit that referenced this issue Jan 12, 2023
* Add snapshot test for #3519 which was fixed via rstudio/bslib#372

* sync package version (GitHub Actions)

* yarn build (GitHub Actions)

* `yarn build` (GitHub Actions)

* Sync package version (GitHub Actions)

Co-authored-by: cpsievert <cpsievert@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Regression Functionality from a previous release no longer works
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants