ijlyttle / bsplus

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

accordions: allow multiple panels open and control which panels are open initially #113

Open warnes opened 1 year ago

warnes commented 1 year ago

This PR adds the function bs_accordion_multi which modifies a bs_accordion object to control whether one or multiple panels can be open at the same time, and which panel (if any) is initially open.

This function is a bit of a hack, as it It is written to modify the HTML code generated by bs_accordion. Ideally these capabilities would be added to the bs_accordion function.

This example code (from the man page):

library(shiny)
library(bsplus)

shinyApp(
  ui = fluidPage(

    tags$header(
      tags$style(
      HTML(
        '
        .panel-heading.collapsed > .panel-title:before {
            float: right !important;
            padding-right: 5px;
            content:"+"
            }

         .panel-heading > .panel-title:before {
           float: right !important;
           font-family: FontAwesome;
           padding-right: 5px;
           content:"-"
         }
         '
        )
      )
    ),

    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_accordion_multi(
        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_accordion_multi(
        multi=FALSE,
        open=c()
        )
      ),

  server = function(input, output) {}
  )

}

yields: image