I wonder whether it'd be better to just have selectInput(multiple=TRUE) and use that as-is; it's not possible to choose the same item twice at a given moment.
However, if you want to do literally as you described, this is an example of how you'd do it:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("letters", "Choose letter(s)", LETTERS,
multiple = TRUE),
actionButton("choose", "Choose")
),
mainPanel(
verbatimTextOutput("list")
)
)
)
server <- function(input, output, session) {
# v$choices will represent the values that have been chosen
v <- reactiveValues(choices = c())
# When the Choose button is clicked, add the current letters to v$choices
# and update the selector
observeEvent(input$choose, {
v$choices <- append(v$choices, input$letters)
updateSelectInput(session, "letters",
choices = LETTERS[!(LETTERS %in% v$choices)]
)
})
output$list <- renderPrint({
v$choices
})
}
shinyApp(ui, server)