NestedMenu-shiny: Shiny bindings for 'NestedMenu'

NestedMenu-shinyR Documentation

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

NestedMenu documentation built on Sept. 17, 2022, 1:05 a.m.