A custom collapsible box with Shiny inputs upon collapse, more or less stolen from shinyBS.

collapseBox(id, title, ..., open = FALSE, style = NULL)

Arguments

id

String specifying the identifier for this object, to use as a field of the Shiny input.

title

String specifying the title of the box for use in the UI.

...

Additional UI elements to show inside the box.

open

Logical scalar indicating whether this box should be open upon initialization.

style

String specifying the box style, defaults to "default".

Value

A HTML tag object containing a collapsible box.

Comments on shinyBS

We would have preferred to use bsCollapse from shinyBS. However, that package does not seem to be under active maintenance, and there are several aspects that make it difficult to use. Specifically, it does not seem to behave well with conditional elements inside the box, and it also does needs a Depends: relationship with shinyBS.

For these reasons, we created our own collapsible box, taking code from shinyBS where appropriate. The underlying Javascript code for this object is present in inst/www and is attached to the search path for Shiny resources upon loading iSEE.

See also

shinyBS, from which the Javascript code was derived.

Author

Aaron Lun, Kevin Rue-Albrecht

Examples

library(shiny)
## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
    fluidRow(
        column(width=6L, collapseBox(
            id="collapseBox_001",
            title="Collapsible box",
            open=FALSE,
            p("A simple paragraph."),
            selectInput("selectInput_001",
                label="Select a letter",
                choices=LETTERS, selected="A"
            )
        )),
        column(width=6L, p(
            "On the left is an example of a", code("collapseBox"), ".", br(),
            "Click on the title of the box to expand or collapse its contents."
        ))
    )
)

shinyApp(ui, server = function(input, output) { })
}