Learn R Programming

yonder (version 0.1.0)

navInput: Page navigation

Description

A reactive input styled as a navigation control. The navigation input can be styled as links, tabs, or pills. A nav input is paired with navContent() and showPane() to create tabbed user interfaces. Observers and reactives are triggered when a nav choice or menu item is clicked. The reactive value of a nav input is NULL or a singleton character string. The value of any menus in the nav input must be retrieved with its own reactive id.

Usage

navInput(id, choices, values = choices, selected = values[[1]], ...,
  appearance = "links", fill = FALSE)

Arguments

id

A character string specifying the id of the reactive input.

choices

A character vector or list of tag elements specifying the navigation items of the navigation input.

values

A character vector specifying custom values for each navigation item, defaults to choices.

selected

One of values specifying which choice is selected by default, defaults to values[[1]].

...

Additional named arguments passed as HTML attributes to the parent element.

appearance

One of "links", "pills", or "tabs" specifying the appearance of the nav input, defaults to "links".

fill

One of TRUE or FALSE specifying if the nav input fills the width of its parent element. If TRUE, the space is divided evenly among the nav items.

Including a menu

Use the reactive id of any nav menus to know when a menu item is clicked.

ui <- navInput(
  id = "navigation",
  choices = list(
    "Item 1",
    "Item 2",
    menuInput(
      id = "navMenu",  # <-
      label = "Item 3",
      choices = c("Choice 1", "Choice 2")
    )
  ),
  values = c("item1", "item2", "item3")
)

server <- function(input, output) { observeEvent(input$navMenu, { cat(paste("Click menu item:", input$navMenu, "\n")) }) }

shinyApp(ui, server)

See Also

Other inputs: buttonGroupInput, buttonInput, checkboxInput, chipInput, fileInput, formInput, groupInput, listGroupInput, menuInput, radioInput, rangeInput, selectInput, sliderInput, textInput

Examples

Run this code
# NOT RUN {
### Nav styled as tabs

navInput(
  id = "tabs1",
  choices = c(
    "Tab 1",
    "Tab 2",
    "Tab 3"
  ),
  selected = "Tab 1",
  appearance = "tabs"
)

### Nav styled as pills

navInput(
  id = "tabs2",
  choices = paste("Tab", 1:3),
  selected = "Tab 1",
  appearance = "pills"
)

### Nav with dropdown

navInput(
  id = "tabs3",
  choices = list(
    "Tab 1",
    menuInput(
      id = NULL,  # <- ignored
      label = "Tab 2",
      choices = c(
        "Action",
        "Another action"
      )
    ),
    "Tab 2"
  ),
  values = c("tab1", "tab2", "tab3")
)

### Full width nav input

navInput(
  id = "tabs4",
  choices = paste("Tab", 1:5),
  values = paste0("tab", 1:5),
  appearance = "pills",
  fill = TRUE
)

### Centering a nav input

navInput(
  id = "tabs5",
  choices = paste("Tab", 1:3)
) %>%
  flex(justify = "center")

# }

Run the code above in your browser using DataLab