Type: | Package |
Title: | A Nested Menu Widget for 'Shiny' Applications |
Version: | 0.2.0 |
Description: | Provides a nested menu widget for usage in 'Shiny' applications. This is useful for hierarchical choices (e.g. continent, country, city). |
License: | GPL-3 |
URL: | https://github.com/stla/NestedMenu |
BugReports: | https://github.com/stla/NestedMenu/issues |
Imports: | fontawesome, htmltools, htmlwidgets, jquerylib, shiny |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.1 |
NeedsCompilation: | no |
Packaged: | 2022-09-16 17:48:55 UTC; SDL96354 |
Author: | Stéphane Laurent [aut, cre], Björn Brala [cph] ('jQuery contextMenu' library) |
Maintainer: | Stéphane Laurent <laurent_step@outlook.fr> |
Repository: | CRAN |
Date/Publication: | 2022-09-16 19:56:09 UTC |
'Nested menu' widget
Description
'Nested menu' HTML widget.
Usage
NestedMenu(
label,
items,
trigger = "left",
style = "primary",
size = NULL,
elementId = NULL
)
Arguments
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 |
Value
A htmlwidget
object.
Shiny bindings for 'NestedMenu'
Description
Output and render functions for using 'NestedMenu' within Shiny applications and interactive Rmd documents.
Usage
NestedMenuOutput(outputId, width = "100%", height = "auto")
renderNestedMenu(expr, env = parent.frame(), quoted = FALSE)
Arguments
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 |
Value
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.
Shiny value
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"]]
.
Examples
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)
}