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

Allow multiple panels to be open at one time #112

Open
warnes opened this issue Jan 6, 2023 · 3 comments
Open

Allow multiple panels to be open at one time #112

warnes opened this issue Jan 6, 2023 · 3 comments

Comments

@warnes
Copy link

warnes commented Jan 6, 2023

I need to allow multiple panels to be open at one time.

The attached file provides the function bs_multi_open, which modifies the HTML generated by bs_accordion to (1) enable/disable multiple panels to be open at one time and (2) specify which (if any) panels are initially open.

This solves #35.

bs_multi_open.txt

Example use:

shinyApp(
ui = fluidPage(

   tags$h2("Multiple Open Panels, Panels 1 and 3 open at page load"),
   bs_accordion(id = "beatles") %>%
     bs_set_opts(panel_type = "success", use_heading_link = TRUE) %>%
     bs_append(title = "John Lennon", content = "Rhythm guitar, vocals") %>%
     bs_append(title = "Paul McCartney", content = "Bass guitar, vocals") %>%
     bs_append(title = "George Harrison", content = "Lead guitar, vocals") %>%
     bs_append(title = "Ringo Starr", content = "Drums, vocals") %>%
     bs_multi_open(
       multi=TRUE,
       open=c(1,3)
       ),

   tags$h2("One Open Panel, No panels open on page load."),
   bs_accordion(id = "fruit") %>%
     bs_set_opts(panel_type = "info") %>%
     bs_append(title = "Apples", content = "An apple a day keeps the doctor away.") %>%
     bs_append(title = "Bannana", content = "Watch out for bannana peels!") %>%
     bs_append(title = "Kumquat", content = "What is a kumquat?!") %>%
     bs_multi_open(
       multi=FALSE,
       open=c()
      )
   ),
     
 server = function(input, output) {}
 )

Which yields:
image

@warnes
Copy link
Author

warnes commented Jan 6, 2023

I'm sorry that I don't have time to properly create a pull request for this.

@warnes
Copy link
Author

warnes commented Jan 6, 2023

I've created pull request #113 to add this functionality through the new function bs_accordion_multi.

@adamcohen3
Copy link

adamcohen3 commented Jun 21, 2023

Thanks for this cool enhancement. I added the function (bs_multi_open) in the .txt to my shiny script. When I set multi = TRUE and open = c(1,3), the first and third panels are initially open, but when I click on a new panel, only the new panel remains open. Is that the intended behavior? Or are all three panels supposed to remain open until the user clicks on an open panel to close it?

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

2 participants