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)
}
Run the code above in your browser using DataLab