Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Allow specification of id tag in bsCollapsePanel #132

Open
warnes opened this issue Jan 6, 2021 · 0 comments · May be fixed by #133
Open

FR: Allow specification of id tag in bsCollapsePanel #132

warnes opened this issue Jan 6, 2021 · 0 comments · May be fixed by #133

Comments

@warnes
Copy link

warnes commented Jan 6, 2021

Feature Request:

Currently, bsCollapsePanel generates a random id tag for the panel. Allowing the user to optionally specify the id tag allows the panel to be accessed directly, including as a target for data-toggle="collapse".

Ideally I would like this code snippet to work:

library(shiny)
library(shinyBS)

app = shinyApp(
  ui =
    fluidPage(
      sidebarLayout(
        sidebarPanel(
          HTML("This button will open and close Panel 1 without using any R code."),
          actionButton(
            inputId="p1Button",
            "Push Me!",
            class="btn btn-primary",
            type="button",
            "data-toggle"="collapse",
            "data-target"="#panel-1",
            "aria-expanded"="false",
            "aria-controls"="collapseExample"
          ),
          selectInput(
            "styleSelect",
            "Select style for Panel 1",
            c("default", "primary", "danger", "warning", "info", "success"))
        ),
        mainPanel(
          bsCollapse(
            id = "collapseExample",
            open = "Panel 2",
            bsCollapsePanel(
              id="panel-1",
              title="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(
              id="panel-2",
              title="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$styleSelect, ({
        updateCollapse(session, "collapseExample", style = list("Panel 1" = input$styleSelect))
      }))
    }
)

(also attached as bsCollapseWithId.R.txt )

as a bonus, it would be nice to have bsCollapseButton and bsCollapseLink functions, so that

 actionButton(
            inputId="p1Button",
            "Push Me!",
            class="btn btn-primary",
            type="button",
            "data-toggle"="collapse",
            "data-target"="#panel-1",
            "aria-expanded"="false",
            "aria-controls"="collapseExample"
          ),

could be replaced with

 actionButton(
            inputId="p1Button",
            "Push Me!",
            target="panel-1",
            parent="collapseExample",
            
          ),
@warnes warnes linked a pull request Jan 6, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant