`accordionItem` allows to create new accordion item that can be passed directly to `accordion` constructor or added on the fly with `addAccordionItem`.

accordionItem(
  id,
  header,
  content,
  class = NULL,
  enroll_callback = TRUE,
  active = FALSE,
  header_class = NULL,
  content_class = NULL,
  ...
)

addAccordionItem(
  accordionId,
  accordionItem,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

id

Unique id of accordion item.

header

Accordion item header.

content

Accordion item content.

class

Class passed to accordion container.

enroll_callback

It `TRUE`, click action on header will enroll the accordion item (and collapse the other existing ones). See accordionEnrollOnClick to see how configure custom on-click enroll element.

active

Should item be enrolled?

header_class

Additional class passed to header container.

content_class

Additional class passed to content container.

...

Extra elements passed to accordion container (before the first accordion item).

accordionId

Id of accordion component where item should be added.

accordionItem

Accordion item to be added.

session

Shiny Session object.

Value

Nested list of `shiny.tag` objects, defining accordion item - its header and content, or no return value in case of using `addAccordionItem` method.

Examples

if (interactive()) {
   library(shiny)
   ui <- fluidPage(
     actionButton("new", "New"),
     accordion(
       "acc",
       accordionItem("first", "Hello", "There", active = TRUE),
       accordionItem("second", "General", "Kenobi")
     )
   )
   server <- function(input, output, session) {}
   shinyApp(ui, server)

  # Accordion with custom styling of header and content (and dynamically added items).
  library(shiny)

  styled_item <- function(id, header_text, content_text, active = FALSE) {
    accordionItem(
      id, header_text, content_text, active = active,
      header_class = "acc-header", content_class = "acc-content"
    )
  }
  ui <- fluidPage(
    tags$head(tags$style(
      ".acc-header, .acc-content {border: 1px solid; border-radius: 5px;}"
    )),
    actionButton("new", "New"),
    accordion(
      "acc",
      styled_item("first", "Hello", "There", TRUE),
      styled_item("second", "General Kenobi", "There")
    )
  )
  server <- function(input, output, session) {
    observeEvent(input$new, {
      addAccordionItem(
        "acc",
        styled_item(
          sample(letters, 1), "I've Been Trained In Your Jedi Arts",
          "By Count Dooku", TRUE
        )
      )
    })
  }

  shinyApp(ui, server)
}