79448614

Date: 2025-02-18 14:39:43
Score: 0.5
Natty:
Report link

I tweaked the example code in the bslib::accordion help to generate a sidebar with accordions as desired (which at the same time can be nested in levels):

Here“s the code:

library(bslib)

items <- lapply(LETTERS[1:5], function(x) {
  
  accordion_panel(paste("Section", x),
                  # p() is useful to display different elements in separate lines 
                  p(paste("Some narrative for section ",x),style = "padding-left: 20px;"),
                  p(paste("More narrative for section ",x),style = "padding-left: 20px;"),
                  accordion_panel(paste("SubSection ", x),
                                  p(actionLink(inputId=x,label=paste0("This is ",x)),
                                    style = "padding-left: 20px;")))
  })

library(shiny)
  
ui <- page_fluid(
  
  page_sidebar(
    
    sidebar = sidebar(
      accordion(!!!items, 
                id = "acc",
                open = F))
    ))
  
server <- function(input, output) {}
  
shinyApp(ui, server)

Screenshot: enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Roberto Ayuto