title: Conditional filtering based on user inputs in Shiny
body: <p>User new to Shiny here. I am trying to create an interactive map which adds circle markers based on 2 groups of users inputs: where each group has 3 possible inputs. I can't seem to figure out how to write the code to properly filter the data and then add the filtered data as circle markers. The filtering logic should go like this:</p>
  
  <p>1) If Religion / Denomination / World = "All", skip that specific filter. (e.g. If Religion 1 = "All", do not filter by Religion 1, but still filter by the rest of the fields if they are not "All").</p>
  
  <p>2) If denomination 1 / 2 is "None", only return the information of the Religion, and exclude the denomination info. (E.g. If Religion 1 = "Christians", Denomination = "None", Geography = "United Kingdom", only the Christian Totals in the UK should be mapped).</p>
  
  <p>3) For all other specific inputs, apply the &amp; operator. (E.g. If Religion 1 = "Christians", Denomination = "Catholics", Geography = "United Kingdom", it should only show Catholics in the UK).</p>
  
  <p>I guess I could just write multiple if / else statements for each possible permutation, but then there will be a lot of conditions and I will have to repeat them twice so that it works for group 1 and group 2.</p>
  
  <p>The year slider input filter should be reactive while the rest of the selectInputs should only work after the user clicks the button.</p>
  
  <p>Here's my UI code:</p>
  
  <pre><code>ui &lt;- fluidPage (
    titlePanel("Religious Affiliations from 1900", windowTitle = "Browser"),
    sidebarLayout(
      sidebarPanel(width = 3,
      conditionalPanel(
        condition = "input.conditionedPanels == 1",
        sliderTextInput("years_map", "Select Year:", 
                        choices = years, selected = 2000,
                        animate = TRUE, grid = TRUE),
        selectInput("religion_1_map", "Religion 1",
                    choices = c("All", religion_names), 
                    selectize = TRUE),  
        selectInput("denom_1_map", "Denomination 1",
                    choices = c("All", "None", denomination_names), 
                    selectize = TRUE),
        selectInput("geography_1_map", "Geography 1", 
                    choices = c("World", all_geography, names(all_regions)), selectize = TRUE),
        selectInput("religion_2_map", "Religion 2",
                    choices = c("All", religion_names),
                    selectize = TRUE),
        selectInput("denom_2_map", "Denomination 2",
                    choices = c("All", "None", denomination_names),
                    selectize = TRUE),
        selectInput("geography_2_map", "Geography 2",
                    choices = c("World", all_geography), selectize = TRUE),
        actionButton("map_button", "Map my choices!")
      ),
    mainPanel(width = 9,
      tabsetPanel(
        tabPanel("Maps", 
        leafletOutput("mymap"),
                 value = 1),
  
        tabPanel("Stacked Area Chart", 
                 "test2",
                 value = 2),
        tabPanel("Pie Chart", value = 3),
        tabPanel("Line Chart", value = 4),
        tabPanel("Statistics", value = 5),
        tabPanel("Data", value = 6),
        id = "conditionedPanels"
        )
  
  
  server &lt;- function(input, output) {
  
  
    output$mymap &lt;- renderLeaflet({
      leaflet() %&gt;% addTiles()
      #Make the map dependent on the button
      input$map_button
    })
  
    year &lt;- reactive({
      all_cleaned %&gt;% filter(year == input$years_map)
    })
  
    religion_1 &lt;- reactiveValues({
      if(input$religion_1_map == "All") {
        year()
      }
      else if(input$religion_1_map == "None") {
        return()
      }
      else {
        year() %&gt;% filter(religion == input$religion_1_map)
      }
    })
  
    denom_1 &lt;- reactive({
      if(input$denom_1_map == "All") {
        religion_1()
      }
      else if(input$denom_1_map == "None") {
        religion_1[!duplicated(religion_1[,'religion']), ]
      }
      else {
        religion_1() %&gt;% filter(denom == input$denom_1_map)
      }
    })
  
    geography_1 &lt;- reactive({
      if(input$geography_1_map == "All") {
        denom_1()
      }
      else if(input$geography_1_map == "None") {
        return()
      }
      else {
        denom_1() %&gt;% filter(country_name %in% input$geography_1_map)
      }
    })
  
    religion_2 &lt;- reactiveValues({
      if(input$religion_2_map == "All") {
        year()
      }
      else if(input$religion_2_map == "None") {
        return()
      }
      else {
        year() %&gt;% filter(religion == input$religion_2_map)
      }
    })
  
    denom_2 &lt;- reactive({
      if(input$denom_2_map == "All") {
        religion_2()
      }
      else if(input$denom_2_map == "None") {
        religion_2[!duplicated(religion_2[,'religion']), ]
      }
      else {
        religion_2() %&gt;% filter(denom == input$denom_2_map)
      }
    })
  
    geography_2 &lt;- reactive({
      if(input$geography_2_map == "All") {
        denom_2()
      }
      else if(input$geography_2_map == "None") {
        return()
      }
      else {
        denom_2() %&gt;% filter(country_name %in% input$geography_2_map)
      }
    })
  
    proxy &lt;- observeEvent(input$map_button, {
      leafletProxy("mymap") %&gt;% 
        addCircleMarkers(data = geography_1()) %&gt;%
        addCircleMarkers(data = geography_2())
    })
  
  }
  </code></pre>
  
  <p><strong>Update: To fix the problem of subsetting from a reactive filter, I simply cleaned my data instead for a workaround. It now works.</strong></p>