title: R Flex Dashboard (Shiny): Dynamic behavior between checkboxgroupinput and selectinput. Prevent selectInput to go back to default values
body: <p>When I check the check boxes, drop down appears with a default value selected. I change selection in drop down and when I uncheck the check box, the value in the drop down goes back to default. I want to retain the values in the dropdown. Here is my reproducible code:</p>
  
  <pre><code>---
  title: "Untitled"
  output: 
    flexdashboard::flex_dashboard:
  runtime: shiny
  ---
  
  ```{r setup, include=FALSE}
  library(flexdashboard)
  library(shiny)
  library(shinydashboard)
  ```
  
  Column {.sidebar}
  -----------------------------------------------------------------------
  
  
  
  ```{r}
  cars &lt;- mtcars
  
  checkboxGroupInput("rowfilters", "Select row filters:",
                 c("Cylinder" = "cyl",
                   "Gear" = "gear"))
  
  renderUI({
    if("cyl" %in% input$rowfilters){
      selectInput('CYL', label = "Select Cylinder:",
              choices = as.character(unique(cars$cyl)), multiple = TRUE, 
  selected = "6")
    }
  })  
  
  
  renderUI({
  
    if("gear" %in% input$rowfilters){
      selectInput('GEAR', label = "Select Gear:",
              choices = as.character(unique(cars$gear)), multiple = TRUE, 
  selected = "4")
    }
  
  })
  
  ```
  </code></pre>
  
  <p>Here when I check "Cylinder" and "Gear", two dropdowns "Select Cylinder", and "Select Gear" appear with a default values. I now change the value in "Select Cylinder:" to 6,4 and 8. Now when I uncheck "Gear", the dropdown "Select Gear" disappears, which is what I want. However, the value in "Select Cylinder" goes back to default value "6". I want "Select Cylinder" to retain my previous selection 6,4, and 8.</p>
  
  <p>Please let me know if you have any suggestions? Thank you. </p>