ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

FR: Allow updating additional attributes in `updatePanel` #131

Open warnes opened 3 years ago

warnes commented 3 years ago

I would like to be able to programmatically update the title of a bsCollapsePanel, but this is not currently supported.

For example, I would like this to work:

library(shiny)
library(shinyBS)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(HTML("This button will open Panel 1 using <code>updateCollapse</code>."),
                 actionButton("p1Button", "Push Me!"),
                 selectInput("styleSelect", "Select style for Panel 1",
                             c("default", "primary", "danger", "warning", "info", "success")),
                 textInput("p2Title", "Panel 1 Title", value = "Panel 1", width = "100%")
    ),
    mainPanel(
      bsCollapse(id = "collapseExample", open = "Panel 2",
                 bsCollapsePanel("Panel 1", "This is a panel with just text ",
                                 "and has the default style. You can change the style in ",
                                 "the sidebar.", style = "info"),
                 bsCollapsePanel("Panel 2", "This panel has a generic plot. ",
                                 "and a 'success' style.", plotOutput("genericPlot"), style = "success")
      )
    )
  )
)

server <- function(input, output, session) {
  output$genericPlot <- renderPlot(plot(rnorm(100)))
  observeEvent(input$p1Button, ({
    updateCollapse(session, "collapseExample", open = "Panel 1")
  }))
  observeEvent(input$styleSelect, ({
    updateCollapse(session, "collapseExample", style = list("Panel 1" = input$styleSelect))
  }))
  # ------- This should change the title of Panel 1 ---------
  observeEvent(input$p1Title, ({
    updateCollapse(session, "collapseExample", title = list("Panel 1" = input$panel1Title))
  }))
  #--------
}

shinyApp(
  ui=ui,
  server=server
)

Please add, :-)