Title: | A Nested Menu Widget for 'Shiny' Applications |
---|---|
Description: | Provides a nested menu widget for usage in 'Shiny' applications. This is useful for hierarchical choices (e.g. continent, country, city). |
Authors: | Stéphane Laurent [aut, cre], Björn Brala [cph] ('jQuery contextMenu' library) |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0 |
Built: | 2024-11-03 05:36:34 UTC |
Source: | https://github.com/stla/nestedmenu |
'Nested menu' HTML widget.
NestedMenu( label, items, trigger = "left", style = "primary", size = NULL, elementId = NULL )
NestedMenu( label, items, trigger = "left", style = "primary", size = NULL, elementId = NULL )
label |
the label of the root button |
items |
list of items for the nested menu; see the Shiny example |
trigger |
the way the menu is triggered: |
style |
a Bootstrap style for the root button: |
size |
size of the root button: |
elementId |
a HTML id; this is usually useless |
A htmlwidget
object.
Output and render functions for using 'NestedMenu' within Shiny applications and interactive Rmd documents.
NestedMenuOutput(outputId, width = "100%", height = "auto") renderNestedMenu(expr, env = parent.frame(), quoted = FALSE)
NestedMenuOutput(outputId, width = "100%", height = "auto") renderNestedMenu(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
dimensions; must be valid CSS measurements
(like |
expr |
an expression that generates a nested menu
(with |
env |
the environment in which to evaluate |
quoted |
Boolean, whether |
NestedMenuOutput
returns an output element that can be
included in a Shiny UI definition, and renderNestedMenu
returns
a shiny.render.function
object that can be included in a Shiny
server definition.
If the outputId
is called "ID"
for example, then the
value of the clicked leaf item is available in the Shiny server in
the reactive variable input[["ID"]]
.
library(NestedMenu) library(shiny) cities <- list( europe = list( name = "Europe", items = list( france = list( name = "France", icon = "fa-cheese", items = list( paris = list(name = "Paris"), lyon = list(name = "Lyon") ) ), italy = list( name = "Italy", icon = "fa-pizza-slice", items = list( roma = list(name = "Roma"), milano = list(name = "Milano") ) ) ) ), america = list( name = "America", items = list( namerica = list( name = "North America", items = list( usa = list( name = "USA", icon = "fa-flag-usa", items = list( chicago = list(name = "Chicago"), newyork = list(name = "New York") ) ), canada = list( name = "Canada", icon = "fa-canadian-maple-leaf", items = list( ottawa = list(name = "Ottawa"), toronto = list(name = "Toronto") ) ) ) ), samerica = list( name = "South America", items = list( brazil = list( name = "Brazil", icon = "fa-lemon", items = list( brasilia = list(name = "Brasilia"), saopolo = list(name = "Sao Polo") ) ), mexico = list( name = "Mexico", icon = "fa-hat-cowboy", items = list( mexicocity = list(name = "Mexico City"), tijuana = list(name = "Tijuana") ) ) ) ) ) ) ) ui <- fluidPage( br(), NestedMenuOutput("menu", height = "auto"), br(), verbatimTextOutput("clicked") ) server <- function(input, output, session){ output[["menu"]] <- renderNestedMenu({ NestedMenu( "Cities", items = cities ) }) output[["clicked"]] <- renderPrint({ input[["menu"]] }) } if(interactive()){ shinyApp(ui, server) }
library(NestedMenu) library(shiny) cities <- list( europe = list( name = "Europe", items = list( france = list( name = "France", icon = "fa-cheese", items = list( paris = list(name = "Paris"), lyon = list(name = "Lyon") ) ), italy = list( name = "Italy", icon = "fa-pizza-slice", items = list( roma = list(name = "Roma"), milano = list(name = "Milano") ) ) ) ), america = list( name = "America", items = list( namerica = list( name = "North America", items = list( usa = list( name = "USA", icon = "fa-flag-usa", items = list( chicago = list(name = "Chicago"), newyork = list(name = "New York") ) ), canada = list( name = "Canada", icon = "fa-canadian-maple-leaf", items = list( ottawa = list(name = "Ottawa"), toronto = list(name = "Toronto") ) ) ) ), samerica = list( name = "South America", items = list( brazil = list( name = "Brazil", icon = "fa-lemon", items = list( brasilia = list(name = "Brasilia"), saopolo = list(name = "Sao Polo") ) ), mexico = list( name = "Mexico", icon = "fa-hat-cowboy", items = list( mexicocity = list(name = "Mexico City"), tijuana = list(name = "Tijuana") ) ) ) ) ) ) ) ui <- fluidPage( br(), NestedMenuOutput("menu", height = "auto"), br(), verbatimTextOutput("clicked") ) server <- function(input, output, session){ output[["menu"]] <- renderNestedMenu({ NestedMenu( "Cities", items = cities ) }) output[["clicked"]] <- renderPrint({ input[["menu"]] }) } if(interactive()){ shinyApp(ui, server) }