Skip to content

Allow multiple panels to be open at one time #112

Open

Description

@warnes

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

Activity

  1. warnes commented on Jan 6, 2023

    @warnes
    Author

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

  2. warnes commented on Jan 6, 2023

    @warnes
    Author

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

  3. adamcohen3 commented on Jun 21, 2023

    @adamcohen3

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions