Skip to content

Documenting id argument to accordion in shiny apps #640

New issue

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

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

Already on GitHub? # to your account

Closed
chrisbrownlie opened this issue Jun 19, 2023 · 1 comment · Fixed by #646
Closed

Documenting id argument to accordion in shiny apps #640

chrisbrownlie opened this issue Jun 19, 2023 · 1 comment · Fixed by #646

Comments

@chrisbrownlie
Copy link

It seems to be the case that the id argument to accordion is required when using it in a {shiny} app, but this wasn't clear from any documentation I could find.

For example, I would have expected the below to work, but it gives an error:

library(shiny)
library(bslib)

ui <- fluidPage(
  theme = bs_theme(version = 5),
  uiOutput("my_accordion")
)

server <- function(input, output, session) {
  output$my_accordion <- renderUI({
    
    # This code taken from help docs
    items <- lapply(LETTERS, function(x) {
      accordion_panel(paste("Section", x), paste("Some narrative for section", x))
    })
    accordion(
      !!!items
    )
    
  })
}

shinyApp(ui, server)

Adding any id to the accordion() call gets rid of the error.

Some possible solutions:

  • If this is just a limitation of the way it is implemented in Bootstrap and there isn't a way around it, then some documentation of either the accordion() return value, or the fact that an id is required in shiny apps even if you don't want to use it, would be good.
  • If it can be fixed so that the above works without an id that would be even better 😁
  • renderAccordion()/accordionOutput() functions?

Or is there an existing way to create dynamic (server-side) accordion()s that I'm unaware of?

Happy to contribute to any of the above if you'd like. Thanks! 👍

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.0 (2023-04-21 ucrt)
#>  os       Windows 10 x64 (build 19044)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.utf8
#>  ctype    English_United Kingdom.utf8
#>  tz       Europe/London
#>  date     2023-06-19
#>  pandoc   3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  ! package     * version date (UTC) lib source
#>  P bslib       * 0.5.0   2023-06-09 [?] CRAN (R 4.3.1)
#>  P cachem        1.0.8   2023-05-01 [?] CRAN (R 4.3.0)
#>  P cli           3.6.1   2023-03-23 [?] CRAN (R 4.3.0)
#>  P digest        0.6.31  2022-12-11 [?] CRAN (R 4.3.0)
#>  P ellipsis      0.3.2   2021-04-29 [?] CRAN (R 4.3.0)
#>  P evaluate      0.21    2023-05-05 [?] CRAN (R 4.3.0)
#>  P fastmap       1.1.1   2023-02-24 [?] CRAN (R 4.3.0)
#>  P fs            1.6.2   2023-04-25 [?] CRAN (R 4.3.0)
#>  P glue          1.6.2   2022-02-24 [?] CRAN (R 4.3.0)
#>  P htmltools     0.5.5   2023-03-23 [?] CRAN (R 4.3.0)
#>  P httpuv        1.6.11  2023-05-11 [?] CRAN (R 4.3.0)
#>  P jquerylib     0.1.4   2021-04-26 [?] CRAN (R 4.3.0)
#>  P jsonlite      1.8.5   2023-06-05 [?] CRAN (R 4.3.0)
#>  P knitr         1.42    2023-01-25 [?] CRAN (R 4.3.0)
#>  P later         1.3.1   2023-05-02 [?] CRAN (R 4.3.0)
#>  P lifecycle     1.0.3   2022-10-07 [?] CRAN (R 4.3.0)
#>  P magrittr      2.0.3   2022-03-30 [?] CRAN (R 4.3.0)
#>  P mime          0.12    2021-09-28 [?] CRAN (R 4.3.0)
#>  P promises      1.2.0.1 2021-02-11 [?] CRAN (R 4.3.0)
#>  P R6            2.5.1   2021-08-19 [?] CRAN (R 4.3.0)
#>  P Rcpp          1.0.10  2023-01-22 [?] CRAN (R 4.3.0)
#>  P reprex        2.0.2   2022-08-17 [?] CRAN (R 4.3.1)
#>  P rlang         1.1.1   2023-04-28 [?] CRAN (R 4.3.0)
#>  P rmarkdown     2.21    2023-03-26 [?] CRAN (R 4.3.0)
#>  P rstudioapi    0.14    2022-08-22 [?] CRAN (R 4.3.0)
#>  P sass          0.4.6   2023-05-03 [?] CRAN (R 4.3.0)
#>  P sessioninfo   1.2.2   2021-12-06 [?] CRAN (R 4.3.0)
#>  P shiny       * 1.7.4   2022-12-15 [?] CRAN (R 4.3.0)
#>  P withr         2.5.0   2022-03-03 [?] CRAN (R 4.3.0)
#>  P xfun          0.39    2023-04-20 [?] CRAN (R 4.3.0)
#>  P xtable        1.8-4   2019-04-21 [?] CRAN (R 4.3.0)
#>  P yaml          2.3.7   2023-01-23 [?] CRAN (R 4.3.0)
#> 
#>  [1] C:/Users/CBROWNLIE/AppData/Local/R/cache/R/renv/library/DN4S-App-b1a01b2a/R-4.3/x86_64-w64-mingw32
#>  [2] C:/Users/CBROWNLIE/AppData/Local/R/cache/R/renv/sandbox/R-4.3/x86_64-w64-mingw32/bc003d48
#>  [3] C:/Users/CBROWNLIE/AppData/Local/Programs/R/R-4.3.0/library
#> 
#>  P ── Loaded and on-disk path mismatch.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Created on 2023-06-19 with reprex v2.0.2

@github-actions
Copy link

This issue has been automatically locked. If you have found a related problem, please open a new issue (with a reproducible example or feature request) and link to this issue.
🙋 Need help? Connect with us on Discord or Posit Community.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant