updateMultiInput | R Documentation |
Change the value of a multi input on the client
updateMultiInput(
session,
inputId,
label = NULL,
selected = NULL,
choices = NULL
)
session |
The session object passed to function given to shinyServer. |
inputId |
The id of the input object. |
label |
The label to set. |
selected |
The values selected. To select none, use |
choices |
The new choices for the input. |
Thanks to Ian Fellows for this one !
multiInput
if (interactive()) {
library(shiny)
library(shinyWidgets)
fruits <- c("Banana", "Blueberry", "Cherry",
"Coconut", "Grapefruit", "Kiwi",
"Lemon", "Lime", "Mango", "Orange",
"Papaya")
ui <- fluidPage(
tags$h2("Multi update"),
multiInput(
inputId = "my_multi",
label = "Fruits :",
choices = fruits,
selected = "Banana",
width = "350px"
),
verbatimTextOutput(outputId = "res"),
selectInput(
inputId = "selected",
label = "Update selected:",
choices = fruits,
multiple = TRUE
),
textInput(inputId = "label", label = "Update label:")
)
server <- function(input, output, session) {
output$res <- renderPrint(input$my_multi)
observeEvent(input$selected, {
updateMultiInput(
session = session,
inputId = "my_multi",
selected = input$selected
)
})
observeEvent(input$label, {
updateMultiInput(
session = session,
inputId = "my_multi",
label = input$label
)
}, ignoreInit = TRUE)
}
shinyApp(ui, server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.