Linked selectInputs - selection persistence

I'm trying to provide an list of options to select from across a few selectInput dropdowns. I want each dropdown to only list items that have not already been selected in any of the others. What I have below will reduce the options for a second selectInput based on already selected values. But making selections in second box resets everything, so cannot e.g., select ABC in 1, DEF in 2, and then have choice of GHIJ in 3.

I was trying an observer but not getting there. Any suggestions on how to implement would be appreciated.

library(shiny)

dataOptions <- c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J')

ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
            wellPanel(                
                uiOutput("dynamicui_g1"),
                uiOutput("dynamicui_g2"),
                uiOutput("dynamicui_g3")
            )),
        mainPanel()        
    )
)

server <- function(input, output, session) {

    output$dynamicui_g1 <- renderUI({
        selectInput(inputId = "group1", label = "Group 1",
                    choices = dataOptions[!(dataOptions %in% c(input$group2, input$group3))],
                    multiple = TRUE)
    })

    output$dynamicui_g2 <- renderUI({
        selectInput(inputId = "group2", label = "Group 2",
                    choices = dataOptions[!(dataOptions %in% c(input$group1, input$group3))],
                    multiple=TRUE)
    })

    output$dynamicui_g3 <- renderUI({
        selectInput(inputId = "group3", label = "Group 3",
                    choices = dataOptions[!(dataOptions %in% c(input$group1, input$group2))],
                    multiple=TRUE)
    })    
}

# Run the application
shinyApp(ui = ui, server = server)

Does this do what you have in mind?

library(shiny)

dataOptions <- c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J')

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      wellPanel(
        selectInput(inputId = "group1", label = "Group 1", choices = dataOptions, multiple = TRUE),
        selectInput(inputId = "group2", label = "Group 2", choices = dataOptions, multiple = TRUE),
        selectInput(inputId = "group3", label = "Group 3", choices = dataOptions, multiple = TRUE)
      )),
    mainPanel()        
  )
)

server <- function(input, output, session) {

  observeEvent(input$group1, {
    updateSelectInput(inputId = "group2",
                      choices = setdiff(dataOptions, c(input$group1, input$group3)),
                      selected = input$group2)
    updateSelectInput(inputId = "group3",
                      choices = setdiff(dataOptions, c(input$group1, input$group2)),
                      selected = input$group3)
  })

  observeEvent(input$group2, {
    updateSelectInput(inputId = "group1",
                      choices = setdiff(dataOptions, c(input$group2, input$group3)),
                      selected = input$group1)
    updateSelectInput(inputId = "group3",
                      choices = setdiff(dataOptions, c(input$group1, input$group2)),
                      selected = input$group3)
  })

  observeEvent(input$group3, {
    updateSelectInput(inputId = "group1",
                      choices = setdiff(dataOptions, c(input$group2, input$group3)),
                      selected = input$group1)
    updateSelectInput(inputId = "group2",
                      choices = setdiff(dataOptions, c(input$group1, input$group3)),
                      selected = input$group2)
  })

}

# Run the application
shinyApp(ui = ui, server = server)

Thanks for taking a look Paul. I'm still about the same behavoir.

I.e., I select say A, B, C for Group 1. Then for Group 2, i do have a shorter list of options not including A,B,C. But as soon as I select anything in Group 2, the Group 1 box resets to blank. Same if I start with any of the other groups.

That does not happen for me. Are you running my sample code as-is (no changes)? The "selected = input$group?" lines are what prevent updates to the list of available choices from blanking out the current selection in each input widget.

Appologies, on a clean session it does! Thank you. I'd originally copy/pasted your version in, commented out the old stuff, not sure why that didn't work the first time.

Pretty sure you saved me between 30 minutes and 40 hours .... I'll never know exactly, but thank you.