| menu | R Documentation |
Creates an interactive menu in the R console allowing users to select items. Inspired by inquirer.js, Python's pick, and Go's survey libraries.
menu(
choices,
prompt = "Select an item:",
type = c("select", "checkbox"),
selected = NULL,
return_index = FALSE
)
choices |
Character vector of choices to display |
prompt |
Prompt message to display (default: "Select an item:") |
type |
Menu type: "select" (single) or "checkbox" (multiple) (default: "select") |
selected |
Pre-selected items (indices or values) |
return_index |
Return indices instead of values (default: FALSE) |
Selected item(s) as character vector or indices, or NULL if cancelled
if (interactive()) {
# Single selection
color <- menu(c("Red", "Green", "Blue"), prompt = "Pick a color:")
# Multiple selection
toppings <- menu(
c("Pepperoni", "Mushrooms", "Olives"),
type = "checkbox",
prompt = "Select toppings:"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.