A panel that slides in from an edge of the viewport.
Usage
el_drawer(
id = NULL,
title = "",
content = NULL,
visible = FALSE,
direction = "rtl",
size = "30%",
modal = TRUE,
with_header = TRUE,
show_close = TRUE,
close_on_press_escape = TRUE,
custom_class = NULL,
append_to_body = FALSE,
destroy_on_close = FALSE,
before_close = NULL,
footer = NULL,
resizable = FALSE,
modal_penetrable = FALSE,
close_on_click_modal = TRUE,
lock_scroll = TRUE,
modal_class = NULL,
header_class = NULL,
body_class = NULL,
footer_class = NULL,
append_to = NULL,
open_delay = NULL,
close_delay = NULL,
z_index = NULL,
header_aria_level = "2",
events = NULL,
session = NULL
)
update_el_drawer(
session = shiny::getDefaultReactiveDomain(),
id,
visible = NULL,
title = NULL,
size = NULL,
direction = NULL,
modal = NULL,
with_header = NULL,
show_close = NULL,
close_on_click_modal = NULL,
close_on_press_escape = NULL,
lock_scroll = NULL
)Arguments
- id
Drawer ID. Auto-generated UUID if
NULL.- title
Header text.
- content
Drawer body. Any tag or tagList, including this package's own components.
- visible
Whether it starts open: Element Plus's
model-value.- direction
Edge it slides from:
"rtl"(from the right, the default),"ltr","ttb"or"btt".- size
Width for a horizontal drawer, height for a vertical one.
- modal
Show the backdrop.
- with_header
Show the header bar.
- show_close
Show the close button in the header.
- close_on_press_escape
Close on Escape.
- custom_class
Extra class name for the panel.
- append_to_body
append_to = "body".- destroy_on_close
Re-create the content each time it opens, and remove it when it closes: inputs inside start from their initial values again.
- before_close
htmltools::JS()functionfunction(done), run when the user closes it – by the cross, the backdrop or Escape; calldone()to let it close.Footer content, usually buttons.
NULLfor none.- resizable
Let the drawer be resized by dragging its inner edge.
- modal_penetrable
Let clicks through the backdrop to the page beneath, when
modal = FALSE.- close_on_click_modal
Close when the backdrop is clicked. (Element UI's
wrapper-closable.)- lock_scroll
Whether the page stops scrolling while it is open.
Extra class names for the backdrop, the header, the body and the footer.
- append_to
A CSS selector for where the overlay goes when it opens, so a container's
overflowortransformcannot clip it. Its components keep working; they are moved, not re-created.- open_delay, close_delay
Milliseconds to wait before opening and closing.
- z_index
The overlay's z-index, instead of the next one Element Plus hands out.
- header_aria_level
The title's
aria-level. Default"2".- events
Element's events to report besides those reported unasked, by name:
events = "node_drop"reportsinput$<id>_node_drop. The component's are listed under "Shiny inputs", and byel_events(); a name it does not have is an error.- session
In
el_drawer(), deprecated: inside a module, wrapidinns(), as for any Shiny input; a session given here namespacesidonce more, with a warning. Inupdate_el_drawer(), the Shiny session, the current one by default, as forshiny::updateTextInput().
Details
Rendered as plain markup carrying Element Plus's own classes, driven by a Shiny input binding rather than a Vue instance, so the body can hold other components from this package.
Shiny inputs
| Input | Reported | Value |
input$<id> | unasked | TRUE while it is open |
input$<id>_open | events = "open" | Triggered before Drawer opening animation begins |
input$<id>_opened | events = "opened" | Triggered after Drawer opening animation ended |
input$<id>_close | events = "close" | Triggered before Drawer closing animation begins |
input$<id>_closed | unasked | Triggered after Drawer closing animation ended |
input$<id>_open_auto_focus | events = "open_auto_focus" | triggers after Drawer opens and content focused |
input$<id>_close_auto_focus | events = "close_auto_focus" | triggers after Drawer closed and content focused |
input$<id>_resize_start | events = "resize_start" | the size, in pixels |
input$<id>_resize | events = "resize" | the size, in pixels |
input$<id>_resize_end | events = "resize_end" | the size, in pixels |
The same list as el_events("el_drawer"), which says how an event's arguments travel.
Element methods
Callable with call_el(): handleClose() closes it the way the user
would, through before_close (closeDrawer(), Element UI's name, too).
Binding
Every argument can follow v_bind() or v_model() except content, footer (content drawn by R); custom_class, append_to_body, destroy_on_close, before_close, resizable, modal_penetrable, modal_class, header_class, body_class, footer_class, append_to, open_delay, close_delay, z_index, header_aria_level (set once, as the overlay is drawn).
Updating from the server
Server-side update for el_drawer(): whether it shows, its title, its
size, the edge it slides from (direction), and how it behaves – modal,
with_header, show_close, close_on_click_modal,
close_on_press_escape, lock_scroll – as Element's props, reactive
there.
update_el_drawer() is called for its side effect and returns NULL invisibly.
Examples
el_drawer("w1", title = "Settings", content = shiny::tags$p("Body"))
#> <div id="w1" class="el-overlay" style="display:none;" data-el-overlay="drawer" data-shiny-island data-el-events="closed" data-visible="false" data-modal="true" data-mask-close="true" data-esc-close="true" data-lock-scroll="true" data-destroy-on-close="false">
#> <div aria-modal="true" aria-labelledby="w1-title" aria-label="Settings" role="dialog" tabindex="-1" class="el-drawer rtl" style="width: 30%;">
#> <header class="el-drawer__header">
#> <span id="w1-title" role="heading" aria-level="2" class="el-drawer__title">Settings</span>
#> <button aria-label="close Settings" type="button" class="el-drawer__close-btn">
#> <i class="el-icon el-drawer__close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="currentColor" d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"></path></svg></i>
#> </button>
#> </header>
#> <div class="el-drawer__body">
#> <p>Body</p>
#> </div>
#> </div>
#> </div>
# Sliding up from the bottom, holding other components
el_drawer(
"w2",
title = "Filters",
direction = "btt",
size = "40%",
content = shiny::tagList(el_input("q"), el_switch("live"))
)
#> <div id="w2" class="el-overlay" style="display:none;" data-el-overlay="drawer" data-shiny-island data-el-events="closed" data-visible="false" data-modal="true" data-mask-close="true" data-esc-close="true" data-lock-scroll="true" data-destroy-on-close="false">
#> <div aria-modal="true" aria-labelledby="w2-title" aria-label="Filters" role="dialog" tabindex="-1" class="el-drawer btt" style="height: 40%;">
#> <header class="el-drawer__header">
#> <span id="w2-title" role="heading" aria-level="2" class="el-drawer__title">Filters</span>
#> <button aria-label="close Filters" type="button" class="el-drawer__close-btn">
#> <i class="el-icon el-drawer__close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="currentColor" d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"></path></svg></i>
#> </button>
#> </header>
#> <div class="el-drawer__body">
#> <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>
if (interactive()) {
# inside a server function
observeEvent(input$go, {
update_el_drawer(session, "settings", visible = TRUE)
})
}