title: Change Selectize Choices But Retain Previously Selected Values
body: <p><strong>Question</strong></p>
  
  <p>I have two dropdowns, the choices available in dd2 are conditional on option selected in dd1. I"m unable to figure out how to change the options of dropdown 2 but retain whatever selection has already been made. I should also be able to drop items from previous selection through dropdown 2.</p>
  
  <p><strong>Example</strong></p>
  
  <p>let's say dd1 is Country: India, England, USA and the respective options in dd2, City: (New Delhi, Mumbai), (London, Birmingham), (New York, Washington DC). I first select India, then Mumbai, then select England, retain Mumbai, and add London. Then I add New York in a similar manner. I now realise that I didn't need Mumbai so I remove it leaving me with London, New York.</p>
  
  <p><strong>Failed Attempts</strong></p>
  
  <p>I'm trying things like appending selections to previously existing vectors and passing the intersection of two vectors to the 'selected' argument but it seems to not work. I'm guessing the circular nature of doing that probably causes problems.</p>
  
  <p><strong>Basic code</strong></p>
  
  <p>To save you guys some time and allow us to have the same reference -</p>
  
  <pre><code># server.r
  
  library(shiny)
  library(data.table)
  countrycity = data.table(
  country = c('India','India','England','England','USA','USA'),
  city = c('New Delhi','Mumbai','London','Birmingham','New York','Washington DC')
  )
  
  shinyServer(function(input, output) {
  
      # dd1: country
      output$chooseCountry &lt;- renderUI({
          selectizeInput(
             "countrSelected", 
             "Country", 
             as.list(c('All',unique(unique(countrycity$country)))),
             options = list(create = TRUE),
             selected = c('All'),
             multiple = TRUE,
             width="120px" 
          )
      })
  
      # filtering list of cities based on the country selected
      citiestoshow = reactive({
  
          countryselected = if ( is.null(input$countryselected) ) {
             unique(countrycity$country)
          } else if ( 'All' %in% input$countryselected ) {
             unique(countrycity$country)
          } else {
             input$countryselected 
          }
  
          countrycity[country %in% countryselected, city]
  
      })
  
      # dd2: city
      output$choosecities &lt;- renderUI({      
  
          selectizeInput(
             'cityselected', 
             label = 'City', 
             choices = as.list(c('All',citiestoshow())),
             options = list(create = TRUE),
             multiple = TRUE,
             width="120px"
          )
  
      })
  
  
  }
  </code></pre>