multiInput | R Documentation |
A user-friendly replacement for select boxes with the multiple attribute
multiInput(
inputId,
label,
choices = NULL,
selected = NULL,
options = NULL,
width = NULL,
choiceNames = NULL,
choiceValues = NULL,
autocomplete = FALSE
)
inputId |
The |
label |
Display label for the control, or |
choices |
List of values to select from. |
selected |
The initially selected value. |
options |
List of options passed to multi ( |
width |
The width of the input, e.g. |
choiceNames |
List of names to display to the user. |
choiceValues |
List of values corresponding to |
autocomplete |
Sets the initial state of the autocomplete property. |
A multiselect control that can be added to the UI of a shiny app.
Fabian Lindfors, "A user-friendly replacement for select boxes with multiple attribute enabled", https://github.com/fabianlindfors/multi.js.
updateMultiInput to update value server-side.
## Only run examples in interactive R sessions
if (interactive()) {
library("shiny")
library("shinyWidgets")
# simple use
ui <- fluidPage(
multiInput(
inputId = "id", label = "Fruits :",
choices = c("Banana", "Blueberry", "Cherry",
"Coconut", "Grapefruit", "Kiwi",
"Lemon", "Lime", "Mango", "Orange",
"Papaya"),
selected = "Banana", width = "350px"
),
verbatimTextOutput(outputId = "res")
)
server <- function(input, output, session) {
output$res <- renderPrint({
input$id
})
}
shinyApp(ui = ui, server = server)
# with options
ui <- fluidPage(
multiInput(
inputId = "id", label = "Fruits :",
choices = c("Banana", "Blueberry", "Cherry",
"Coconut", "Grapefruit", "Kiwi",
"Lemon", "Lime", "Mango", "Orange",
"Papaya"),
selected = "Banana", width = "400px",
options = list(
enable_search = FALSE,
non_selected_header = "Choose between:",
selected_header = "You have selected:"
)
),
verbatimTextOutput(outputId = "res")
)
server <- function(input, output, session) {
output$res <- renderPrint({
input$id
})
}
shinyApp(ui = ui, server = server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.