A navigation menu, vertical or horizontal, with submenus nested to any depth.
Usage
el_menu(
id = NULL,
items = list(),
default_active = NULL,
mode = "vertical",
collapse = FALSE,
unique_opened = FALSE,
background_color = NULL,
text_color = NULL,
active_text_color = NULL,
default_openeds = NULL,
menu_trigger = NULL,
collapse_transition = NULL,
router = NULL,
close_on_click_outside = NULL,
ellipsis = NULL,
ellipsis_icon = NULL,
hide_timeout = NULL,
persistent = NULL,
popper_class = NULL,
popper_effect = NULL,
popper_offset = NULL,
popper_style = NULL,
show_timeout = NULL,
class = NULL,
style = NULL,
width = NULL,
slots = NULL,
events = NULL,
on = NULL,
session = NULL
)
update_el_menu(
session = shiny::getDefaultReactiveDomain(),
id,
default_active = NULL,
collapse = NULL,
mode = NULL,
unique_opened = NULL,
background_color = NULL,
text_color = NULL,
active_text_color = NULL,
menu_trigger = NULL,
collapse_transition = NULL,
router = NULL,
close_on_click_outside = NULL,
ellipsis = NULL,
ellipsis_icon = NULL,
hide_timeout = NULL,
persistent = NULL,
popper_class = NULL,
popper_effect = NULL,
popper_offset = NULL,
popper_style = NULL,
show_timeout = NULL
)Arguments
- id
Menu ID (auto-generated if NULL).
- items
A list of items, each an
el_menu_item(),el_sub_menu()orel_menu_item_group()– or a list withindex(the value reported when selected),label(ortitle, Element's name for it), and optionallyicon(an icon's name, such as"House"),disabled,route(forrouter = TRUE), orchildrenfor a submenu. A submenu may also carry Element Plus's sub-menu props:popper_class,popper_style,show_timeout,hide_timeout,teleported,popper_offset, and its expand and collapse icons (expand_close_icon,expand_open_icon,collapse_close_icon,collapse_open_icon). An item withgroup = TRUEbecomes a titled group of itschildrenrather than a submenu.Clicking an item reports
input$<id>(the index selected) andinput$<id>_item_click(the index clicked).- default_active
Index of the initially selected item: Element Plus's
default-active. Inupdate_el_menu(), the item to select.- mode
"vertical"(default) or"horizontal".- collapse
Collapse to icons only. Vertical menus only.
- unique_opened
Keep only one submenu open at a time.
- background_color, text_color, active_text_color
Menu colours.
- default_openeds
Character vector of sub-menu indexes open at start.
How a horizontal sub-menu opens:
"hover"(default) or"click".- collapse_transition
Whether to animate collapsing. Default
TRUE.- router
Whether to use vue-router mode, taking each index – or an item's
route– as a path: a click navigates the page's router,vue_router(), which the page needs, and the active item follows the route however it changes (back and forward,update_vue_router()), asinput$<id>does.- close_on_click_outside
Optional, whether menu is collapsed when clicking outside. Element Plus's
close-on-click-outside(boolean).- ellipsis
Whether the menu is ellipsis (available only in horizontal mode). Element Plus's
ellipsis(boolean).- ellipsis_icon
Custom ellipsis icon (available only in horizontal mode and ellipsis is true). Element Plus's
ellipsis-icon(string / Component). An icon's name, such as"Search".- hide_timeout
Control timeout for all menus before hiding. Element Plus's
hide-timeout(number).- persistent
When menu inactive and
persistentisfalse, dropdown menu will be destroyed. Element Plus'spersistent(boolean).- popper_class
Custom class name for all popup menus and titles' tooltips. Element Plus's
popper-class(string).- popper_effect
Tooltip theme, built-in theme:
dark/lightwhen menu is collapsed. Element Plus'spopper-effect('dark' | 'light' / string).- popper_offset
Offset of the popper (effective for all submenus). Element Plus's
popper-offset(number).- popper_style
Custom style for all popup menus and titles' tooltips. Element Plus's
popper-style(string / object).- show_timeout
Control timeout for all menus before showing. Element Plus's
show-timeout(number).- class, style
Extra classes and inline style on the menu, as Element passes them to its root: Element's examples style theirs by a class of their own.
- width
Component width, as a CSS unit –
"200px","50%", or a number taken as pixels. Element's own markup carries it, so it behaves like thewidthargument of a Shiny input.- slots
Named list of Element slot contents, such as
list(title = shiny::tags$b("Bold")). A shiny.element component given here is absorbed rather than nested. For a scoped slot, write the template withtemplate().- 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.- on
Handlers of your own, for an event not reported or to send something else: a named list of
JS()functions, one per event – Element's, or a DOM event with Vue's modifiers ("keyup.enter"). Each is called withreportand the event's arguments;report(name, value)setsinput$<id>_<name>. Seeel_widget().- session
In
el_menu(), deprecated: inside a module, wrapidinns(), as for any Shiny input; a session given here namespacesidonce more, with a warning. Inupdate_el_menu(), the Shiny session, the current one by default, as forshiny::updateTextInput().
Shiny inputs
| Input | Reported | Value |
input$<id> | unasked | the index of the selected item |
input$<id>_path | unasked | the indexes down to it |
input$<id>_open | events = "open" | list(index, path) of the submenu |
input$<id>_close | events = "close" | list(index, path) of the submenu |
The same list as el_events("el_menu"), which says how an event's arguments travel.
Element methods
Callable with call_el():
Binding
Every argument can follow v_bind() or v_model() except items (the items, drawn by R); class, style (the root's attribute, drawn by R); width (the mount point's style).
Updating from the server
update_el_menu() changes the component from the server.
Every other argument of el_menu() that can change once it is
drawn is an argument here too, under the same name. One left NULL
stays as it is; NA returns it to Element's default.
update_el_menu() is called for its side effect and returns NULL invisibly.
Examples
el_menu(
id = "nav",
default_active = "home",
items = list(
list(index = "home", label = "Home", icon = "House"),
list(
index = "products",
label = "Products",
icon = "Goods",
children = list(
list(index = "products-all", label = "All"),
list(index = "products-new", label = "New")
)
),
list(index = "help", label = "Help", disabled = TRUE)
)
)
#> <div id="nav" data-shiny-vue style="display: contents">
#> <script type="text/x-template" data-shiny-vue-template><div id="nav_container" style="display: contents">
#> <el-menu v-bind="$optional('menu')" :default-active="active" :mode="mode" :collapse="collapse" :unique-opened="uniqueOpened" @select="handleSelect">
#> <el-menu-item index="home" @click="elMenuItemClick("home")">
#> <el-icon><House /></el-icon>
#> <span>Home</span>
#> </el-menu-item>
#> <el-sub-menu index="products">
#> <template v-slot:title>
#> <el-icon><Goods /></el-icon>
#> <span>Products</span>
#> </template>
#> <el-menu-item index="products-all" @click="elMenuItemClick("products-all")">
#> <span>All</span>
#> </el-menu-item>
#> <el-menu-item index="products-new" @click="elMenuItemClick("products-new")">
#> <span>New</span>
#> </el-menu-item>
#> </el-sub-menu>
#> <el-menu-item index="help" :disabled="true" @click="elMenuItemClick("help")">
#> <span>Help</span>
#> </el-menu-item>
#> </el-menu>
#> </div></script>
#> <script type="application/json" data-shiny-vue-options>{"options":{"data":{"active":"home","mode":"vertical","collapse":false,"uniqueOpened":false,"path":[],"backgroundColor":null,"textColor":null,"activeTextColor":null,"defaultOpeneds":null,"menuTrigger":null,"collapseTransition":null,"router":null,"closeOnClickOutside":null,"ellipsis":null,"ellipsisIcon":null,"hideTimeout":null,"persistent":null,"popperClass":null,"popperEffect":null,"popperOffset":null,"popperStyle":null,"showTimeout":null},"methods":{"elMenuItemClick":"function(index) { window.Shiny && Shiny.setInputValue && Shiny.setInputValue('nav_item_click', index, {priority: 'event'}); }","handleSelect":"function(index, indexPath) { var self = this; self.path = indexPath; window.Shiny && Shiny.setInputValue && Shiny.setInputValue('nav_path', indexPath); if (self.router && self.$router) return; self.active = index; }"},"watch":{"$route.path":{"handler":"function(p) { if (!this.router || !this.$router || p === undefined) return; this.active = p; window.Shiny && Shiny.setInputValue && Shiny.setInputValue('nav', p); }","immediate":true}},"mounted":"function() { var self = this; var send = function() { window.Shiny && Shiny.setInputValue && Shiny.setInputValue(\"nav_path\", self.path); }; if (window.Shiny && Shiny.shinyapp && typeof Shiny.shinyapp.isConnected === 'function' && Shiny.shinyapp.isConnected()) { send(); } else if (window.jQuery) { jQuery(document).one('shiny:connected', send); } var prev = self._svReport; self._svReport = function() { if (prev) prev(); self.$nextTick(send); }; }"},"input":"active || null","rate":null,"type":null,"use":["shinyElement.plugin"],"optional":{"menu":{"background-color":"backgroundColor","text-color":"textColor","active-text-color":"activeTextColor","default-openeds":"defaultOpeneds","menu-trigger":"menuTrigger","collapse-transition":"collapseTransition","router":"router","close-on-click-outside":"closeOnClickOutside","ellipsis":"ellipsis","ellipsis-icon":"ellipsisIcon","hide-timeout":"hideTimeout","persistent":"persistent","popper-class":"popperClass","popper-effect":"popperEffect","popper-offset":"popperOffset","popper-style":"popperStyle","show-timeout":"showTimeout"}},"evals":["options.methods.elMenuItemClick","options.methods.handleSelect","options.watch.$route\\.path.handler","options.mounted"]}</script>
#> </div>
# Horizontal, as a top bar
el_menu(
id = "topnav",
mode = "horizontal",
default_active = "a",
items = list(
list(index = "a", label = "One"),
list(index = "b", label = "Two")
)
)
#> <div id="topnav" data-shiny-vue style="display: contents">
#> <script type="text/x-template" data-shiny-vue-template><div id="topnav_container" style="display: contents">
#> <el-menu v-bind="$optional('menu')" :default-active="active" :mode="mode" :collapse="collapse" :unique-opened="uniqueOpened" @select="handleSelect">
#> <el-menu-item index="a" @click="elMenuItemClick("a")">
#> <span>One</span>
#> </el-menu-item>
#> <el-menu-item index="b" @click="elMenuItemClick("b")">
#> <span>Two</span>
#> </el-menu-item>
#> </el-menu>
#> </div></script>
#> <script type="application/json" data-shiny-vue-options>{"options":{"data":{"active":"a","mode":"horizontal","collapse":false,"uniqueOpened":false,"path":[],"backgroundColor":null,"textColor":null,"activeTextColor":null,"defaultOpeneds":null,"menuTrigger":null,"collapseTransition":null,"router":null,"closeOnClickOutside":null,"ellipsis":null,"ellipsisIcon":null,"hideTimeout":null,"persistent":null,"popperClass":null,"popperEffect":null,"popperOffset":null,"popperStyle":null,"showTimeout":null},"methods":{"elMenuItemClick":"function(index) { window.Shiny && Shiny.setInputValue && Shiny.setInputValue('topnav_item_click', index, {priority: 'event'}); }","handleSelect":"function(index, indexPath) { var self = this; self.path = indexPath; window.Shiny && Shiny.setInputValue && Shiny.setInputValue('topnav_path', indexPath); if (self.router && self.$router) return; self.active = index; }"},"watch":{"$route.path":{"handler":"function(p) { if (!this.router || !this.$router || p === undefined) return; this.active = p; window.Shiny && Shiny.setInputValue && Shiny.setInputValue('topnav', p); }","immediate":true}},"mounted":"function() { var self = this; var send = function() { window.Shiny && Shiny.setInputValue && Shiny.setInputValue(\"topnav_path\", self.path); }; if (window.Shiny && Shiny.shinyapp && typeof Shiny.shinyapp.isConnected === 'function' && Shiny.shinyapp.isConnected()) { send(); } else if (window.jQuery) { jQuery(document).one('shiny:connected', send); } var prev = self._svReport; self._svReport = function() { if (prev) prev(); self.$nextTick(send); }; }"},"input":"active || null","rate":null,"type":null,"use":["shinyElement.plugin"],"optional":{"menu":{"background-color":"backgroundColor","text-color":"textColor","active-text-color":"activeTextColor","default-openeds":"defaultOpeneds","menu-trigger":"menuTrigger","collapse-transition":"collapseTransition","router":"router","close-on-click-outside":"closeOnClickOutside","ellipsis":"ellipsis","ellipsis-icon":"ellipsisIcon","hide-timeout":"hideTimeout","persistent":"persistent","popper-class":"popperClass","popper-effect":"popperEffect","popper-offset":"popperOffset","popper-style":"popperStyle","show-timeout":"showTimeout"}},"evals":["options.methods.elMenuItemClick","options.methods.handleSelect","options.watch.$route\\.path.handler","options.mounted"]}</script>
#> </div>
if (interactive()) {
# inside a server function
observeEvent(input$go, {
update_el_menu(session, "nav", default_active = "data")
})
}