Advertisement
karstenw

dynamic accordion

May 24th, 2024
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.98 KB | Source Code | 0 0
  1. ui <- bslib::page_sidebar(
  2.     sidebar=bslib::sidebar(
  3.         open="always",
  4.         position="right",
  5.         shiny::selectInput(
  6.             inputId="acc_title",
  7.             label="Accordion Panel's title",
  8.             choices=c("Title 1", "Title 2"),
  9.             selected="Title 1",
  10.             multiple=FALSE
  11.         )
  12.     ),
  13.     bslib::card(
  14.         "Some content",
  15.         bslib::card_footer(
  16.             bslib::accordion(
  17.                 id="acc",
  18.                 open=FALSE,
  19.                 multiple=FALSE,
  20.                 bslib::accordion_panel(
  21.                     value="acc_panel", # not "id"
  22.                     "Title 1",
  23.                     "Accordion's content."
  24.                 )
  25.             )
  26.         )
  27.     )
  28. )
  29. server = function(input, output, session) {
  30.     shiny::observeEvent(input$acc_title, {
  31.         bslib::accordion_panel_update( # <-- crucial part
  32.             id="acc",
  33.             target="acc_panel",
  34.             title = input$acc_title
  35.         )
  36.     })
  37. }
  38. shiny::runApp(shinyApp(ui, server))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement