ijlyttle / bsplus

Shiny and R Markdown addons to Bootstrap 3
http://ijlyttle.github.io/bsplus/
Other
147 stars 23 forks source link

Allow multiple panels to be open at one time #112

Open warnes opened 1 year ago

warnes commented 1 year ago

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 commented 1 year ago

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

warnes commented 1 year ago

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

adamcohen3 commented 1 year ago

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?