Collapsible panels. Several can be open at once unless accordion = TRUE.
Usage
el_collapse(
id = NULL,
items = list(),
value = character(0),
accordion = FALSE,
expand_icon_position = "right",
before_collapse = NULL,
session = NULL
)
update_el_collapse(
session = shiny::getDefaultReactiveDomain(),
id,
value = NULL,
accordion = NULL,
expand_icon_position = NULL,
before_collapse = NULL
)Arguments
- id
Collapse ID. Auto-generated UUID if
NULL.- items
A list of panels, each an
el_collapse_item()– or a named list with the same fields:- name
Unique panel identifier (string). Required.
- title
Panel header text. Required.
- content
Panel body. Any tag or tagList, including this package's own components.
- disabled
Whether the header is disabled. Default
FALSE.- icon
The expand icon, by name (default
"ArrowRight"), or a tag.
- value
Character vector of initially open panel names. In accordion mode only the first is used.
- accordion
Single-open accordion mode. Default
FALSE.- expand_icon_position
Where each header's icon sits:
"right"(the default) or"left".- before_collapse
JS()functionfunction(name), run before a panel opens or closes: returnfalse, or a promise that resolves tofalse, to keep it as it is.- session
In
el_collapse(), deprecated: inside a module, wrapidinns(), as for any Shiny input; a session given here namespacesidonce more, with a warning. Inupdate_el_collapse(), the Shiny session, the current one by default, as forshiny::updateTextInput().
Details
Rendered as plain markup carrying Element's own classes, driven by a Shiny
input binding rather than a Vue instance. That is what lets a panel hold
other components from this package: a Vue instance mounted here would
rebuild the DOM underneath them, detaching them from the server. See
.claude/docs/lessons.md.
Shiny inputs
| Input | Reported | Value |
input$<id> | unasked | the names of the open panels |
The same list as el_events("el_collapse"), which says how an event's arguments travel.
Updating from the server
Server-side update for el_collapse(): the open panels, accordion,
expand_icon_position and before_collapse (NA for none).
update_el_collapse() is called for its side effect and returns NULL invisibly.
Examples
el_collapse(
"col1",
items = list(
list(name = "p1", title = "Panel 1", content = shiny::tags$p("Content 1")),
list(name = "p2", title = "Panel 2", content = shiny::tags$p("Content 2"))
),
value = "p1"
)
#> <div id="col1" class="el-collapse el-collapse-icon-position-right" data-el-collapse="true" data-shiny-island data-accordion="false">
#> <div class="el-collapse-item is-active" data-el-name="p1">
#> <div id="col1-head-p1" role="button" tabindex="0" aria-expanded="true" aria-controls="col1-content-p1" aria-describedby="col1-content-p1" class="el-collapse-item__header is-active">
#> <span class="el-collapse-item__title">Panel 1</span>
#> <i class="el-icon el-collapse-item__arrow is-active" data-el-icon="ArrowRight"></i>
#> </div>
#> <div id="col1-content-p1" role="region" aria-hidden="false" aria-labelledby="col1-head-p1" class="el-collapse-item__wrap">
#> <div class="el-collapse-item__content">
#> <p>Content 1</p>
#> </div>
#> </div>
#> </div>
#> <div class="el-collapse-item" data-el-name="p2">
#> <div id="col1-head-p2" role="button" tabindex="0" aria-expanded="false" aria-controls="col1-content-p2" aria-describedby="col1-content-p2" class="el-collapse-item__header">
#> <span class="el-collapse-item__title">Panel 2</span>
#> <i class="el-icon el-collapse-item__arrow" data-el-icon="ArrowRight"></i>
#> </div>
#> <div id="col1-content-p2" role="region" aria-hidden="true" aria-labelledby="col1-head-p2" class="el-collapse-item__wrap" style="display:none">
#> <div class="el-collapse-item__content">
#> <p>Content 2</p>
#> </div>
#> </div>
#> </div>
#> </div>
# A panel can hold other components
el_collapse(
"col2",
items = list(
list(
name = "f",
title = "Filters",
content = shiny::tagList(el_input("q"), el_switch("live"))
)
)
)
#> <div id="col2" class="el-collapse el-collapse-icon-position-right" data-el-collapse="true" data-shiny-island data-accordion="false">
#> <div class="el-collapse-item" data-el-name="f">
#> <div id="col2-head-f" role="button" tabindex="0" aria-expanded="false" aria-controls="col2-content-f" aria-describedby="col2-content-f" class="el-collapse-item__header">
#> <span class="el-collapse-item__title">Filters</span>
#> <i class="el-icon el-collapse-item__arrow" data-el-icon="ArrowRight"></i>
#> </div>
#> <div id="col2-content-f" role="region" aria-hidden="true" aria-labelledby="col2-head-f" class="el-collapse-item__wrap" style="display:none">
#> <div class="el-collapse-item__content">
#> <div id="q" data-shiny-vue style="display: contents">
#> <script type="text/x-template" data-shiny-vue-template><div id="q_container" style="display: contents">
#> <el-input v-bind="$optional('input')" v-model="value" :type="type" :disabled="disabled" :readonly="readonly" :clearable="clearable" :show-password="showPassword" :show-word-limit="showWordLimit" :autosize="autosize" :prefix-icon="prefixIcon" :suffix-icon="suffixIcon" @change="handleChange"></el-input>
#> </div></script>
#> <script type="application/json" data-shiny-vue-options>{"options":{"data":{"value":"","type":"text","disabled":false,"readonly":false,"clearable":false,"showPassword":false,"showWordLimit":false,"autosize":false,"prefixIcon":null,"suffixIcon":null,"size":null,"placeholder":null,"maxlength":null,"rows":null,"label":null,"autocomplete":null,"autofocus":null,"name":null,"form":null,"minlength":null,"max":null,"min":null,"step":null,"resize":null,"tabindex":null,"validateEvent":null,"ariaLabel":null,"clearIcon":null,"countGraphemes":null,"formatter":null,"inputStyle":null,"inputmode":null,"parser":null,"wordLimitPosition":null},"methods":{"handleChange":"function(value) { }"}},"input":"value","rate":{"policy":"debounce","delay":250},"type":null,"use":["shinyElement.plugin"],"optional":{"input":{"size":"size","placeholder":"placeholder","maxlength":"maxlength","rows":"rows","label":"label","autocomplete":"autocomplete","autofocus":"autofocus","name":"name","form":"form","minlength":"minlength","max":"max","min":"min","step":"step","resize":"resize","tabindex":"tabindex","validate-event":"validateEvent","aria-label":"ariaLabel","clear-icon":"clearIcon","count-graphemes":"countGraphemes","formatter":"formatter","input-style":"inputStyle","inputmode":"inputmode","parser":"parser","word-limit-position":"wordLimitPosition"}},"evals":["options.methods.handleChange"]}</script>
#> </div>
#> <div id="live" data-shiny-vue style="display: contents">
#> <script type="text/x-template" data-shiny-vue-template><div id="live_container" style="display: contents">
#> <el-switch v-bind="$optional('switch')" v-model="value" :disabled="disabled" :active-text="activeText" :inactive-text="inactiveText" :style="{ '--el-switch-on-color': activeColor || undefined, '--el-switch-off-color': inactiveColor || undefined, '--el-switch-border-color': borderColor || undefined }" :active-value="activeValue" :inactive-value="inactiveValue" @change="handleChange"></el-switch>
#> </div></script>
#> <script type="application/json" data-shiny-vue-options>{"options":{"data":{"value":false,"disabled":false,"activeText":"","inactiveText":"","activeColor":"","inactiveColor":"","activeValue":true,"inactiveValue":false,"width":null,"name":null,"validateEvent":null,"activeActionIcon":null,"activeIcon":null,"ariaLabel":null,"beforeChange":null,"borderColor":null,"inactiveActionIcon":null,"inactiveIcon":null,"inlinePrompt":null,"loading":null,"size":null,"tabindex":null},"methods":{"handleChange":"function(value) { }"}},"input":"value","rate":null,"type":null,"use":["shinyElement.plugin"],"optional":{"switch":{"width":"width","name":"name","validate-event":"validateEvent","active-action-icon":"activeActionIcon","active-icon":"activeIcon","aria-label":"ariaLabel","before-change":"beforeChange","border-color":"borderColor","inactive-action-icon":"inactiveActionIcon","inactive-icon":"inactiveIcon","inline-prompt":"inlinePrompt","loading":"loading","size":"size","tabindex":"tabindex"}},"evals":["options.methods.handleChange"]}</script>
#> </div>
#> </div>
#> </div>
#> </div>
#> </div>
if (interactive()) {
# inside a server function
observeEvent(input$go, {
update_el_collapse(session, "panels", value = "filters")
})
}