Change the value of a drop input on the client
Examples
if (interactive()) {
library(shiny)
library(esquisse)
myChoices <- tagList(
list(icon("home"), style = "width: 100px;"),
list(icon("flash"), style = "width: 100px;"),
list(icon("cogs"), style = "width: 100px;"),
list(icon("fire"), style = "width: 100px;"),
list(icon("users"), style = "width: 100px;"),
list(icon("info"), style = "width: 100px;")
)
ui <- fluidPage(
tags$h2("Update Drop Input"),
fluidRow(
column(
width = 6,
dropInput(
inputId = "mydrop",
choicesNames = myChoices,
choicesValues = c("home", "flash", "cogs", "fire", "users", "info"),
dropWidth = "220px"
),
verbatimTextOutput(outputId = "res")
),
column(
width = 6,
actionButton("home", "Select home"),
actionButton("flash", "Select flash"),
actionButton("cogs", "Select cogs"),
actionButton("fire", "Select fire"),
actionButton("users", "Select users"),
actionButton("info", "Select info"),
checkboxGroupInput(
inputId = "disabled",
label = "Choices to disable",
choices = c("home", "flash", "cogs", "fire", "users", "info")
),
actionButton("disable", "Disable")
)
)
)
server <- function(input, output, session) {
output$res <- renderPrint({
input$mydrop
})
observeEvent(input$home, {
updateDropInput(session, "mydrop", "home")
})
observeEvent(input$flash, {
updateDropInput(session, "mydrop", "flash")
})
observeEvent(input$cogs, {
updateDropInput(session, "mydrop", "cogs")
})
observeEvent(input$fire, {
updateDropInput(session, "mydrop", "fire")
})
observeEvent(input$users, {
updateDropInput(session, "mydrop", "users")
})
observeEvent(input$info, {
updateDropInput(session, "mydrop", "info")
})
observeEvent(input$disable, {
if (!is.null(input$disabled)) {
updateDropInput(session, "mydrop", disabled = input$disabled)
} else {
updateDropInput(session, "mydrop", disabled = character(0))
}
})
}
shinyApp(ui, server)
}