Package 'NestedMenu'

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

Help Index


'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: "left" to trigger on a left-click, "right" to trigger on a right-click, "hover" to trigger on hover

style

a Bootstrap style for the root button: "primary", "info", "success", "warning" or "danger"

size

size of the root button: NULL (normal), "lg" (large), "sm" (small) or "xs" (extra-small)

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 "100%", "400px", "auto")

expr

an expression that generates a nested menu (with NestedMenu)

env

the environment in which to evaluate expr.

quoted

Boolean, whether expr is a quoted expression

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)
}