title: Selecting markers based on characteristics in R - Leaflet - Shiny
body: <p>I am writing a Leaflet map in R and integrating it with shiny. I have three questions to ask and the code will be at the bottom with the problems highlighted:</p>
  
  <ol>
  <li><p>On this map, I have random markers, each representing an aquatic environment. I also have a drop-down list allowing you to select the specific environment you want, which will only select those markers corresponding to the environment. I have created the absolutePanel which allows you to do this but cannot get the script to select for the markers using the reactive function.</p></li>
  <li><p>Not an important factor, but will be useful. I have highlighted the countries that contain the markers, but when you move the slider to select for the years and corresponding markers you want to view, "empty" countries still remain. As the markers are removed based on the year, I want the countries no longer containing markers to be highlighted. Also it seems very slow. </p></li>
  <li><p>Only for interest sake, but is there a map like "OpenStreetMap.Mapink" that is completely in English? </p></li>
  </ol>
  
  <p>Below is the data file linked, as well as the script for the map:</p>
  
  <p><a href="https://drive.google.com/drive/folders/10anPY-I-B13zTQ7cjUsjQoJDcMK4NCXb?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/drive/folders/10anPY-I-B13zTQ7cjUsjQoJDcMK4NCXb?usp=sharing</a></p>
  
  <pre><code>library(shiny)
  library(leaflet)
  library(maps)
  library(htmltools)
  library(htmlwidgets)
  library(dplyr)
  
  
  ###############################
  
  map_data  &lt;- read.csv("example1.csv", header = TRUE)
  
  countries &lt;- map_data %&gt;%
    distinct(DOI, Country.s., .keep_all = TRUE)
  
  area_data &lt;- map_data %&gt;%
    filter(Area.Site == "Area")
  
  site_data &lt;- map_data %&gt;% 
    filter(Area.Site == "Site")
  
  sampling_count &lt;- count(site_data, "Country.s.")
  country_count &lt;- count(countries, "Country.s.")
  
  bounds &lt;- map("world", area_data$Country.s., fill = TRUE, plot = FALSE)
  
  bounds$studies &lt;- country_count$freq[match(gsub("\\:.*", "", bounds$names), country_count$Country.s.)]
  bounds$sampling_points &lt;- sampling_count$freq[match(gsub("\\:.*", "", bounds$names), sampling_count$Country.s.)]
  bounds$year &lt;- site_data$Publication_Year[match(gsub("\\:.*", "", bounds$names), site_data$Country.s.)]
  
  
  ui &lt;- bootstrapPage(
    tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
    leafletOutput("map", 
                  width = "100%",
                  height = "100%"),
    ################################
    #Question 1 
    ################################
    absolutePanel(top = 5, right = 320,
                  selectInput("environment", "Sampling Source: ",
                              c("All" = "P&amp;C",
                                "Surface Water" = "SW",
                                "Wastewater" = "WW",
                                "Sea Water" = "Sea"))),
    ################################
    #Question 1 
    ################################
    absolutePanel(bottom = 5, right = 320,
                  sliderInput("year", "Publication Year(s)", min(site_data$Publication_Year), max(site_data$Publication_Year),
                              value = range(site_data$Publication_Year), step = 1, sep = "", width = 500))
  )
  
  
  server &lt;- function(input, output, session) {
  
    marker_data &lt;- reactive({
      site_data[site_data$Publication_Year &gt;= input$year[1] &amp; site_data$Publication_Year &lt;= input$year[2],]
    })
  
    area_s_data &lt;- reactive({
      area_data[area_data$Publication_Year &gt;= input$year[1] &amp; area_data$Publication_Year &lt;= input$year[2],]
    })
  
    border_data &lt;- reactive({
      bounds[bounds$year &gt;= input$year[1] &amp; bounds$year  &lt;= input$year[2],]
    })
  
  
  
    output$map &lt;- renderLeaflet({
      leaflet(map_data, options = leafletOptions(worldCopyJump = TRUE)) %&gt;%
  ################################
  #Question 3
  ################################
        addProviderTiles("OpenStreetMap.Mapnik")
  ################################
  #Question 3
  ################################
  
    })
  
    observe({
  
      leafletProxy("map", data = marker_data()) %&gt;%
        clearMarkers() %&gt;%
        addAwesomeMarkers(lat = ~Latitude,
                          lng = ~Longitude,
                          label = ~paste(Aquatic_Environment_Type))
  
    })
    ################################
    #Question 2
    ################################
    observe({
  
      leafletProxy("map", data = area_s_data()) %&gt;%
        clearShapes() %&gt;%
        addCircles(lat = ~Latitude, 
                   lng = ~Longitude,
                   radius = ~as.numeric(Area_Radius_Meter),
                   color = "blue",
                   weight = 1,
                   highlightOptions = highlightOptions(color = "red",
                                                       weight = 2,
                                                       bringToFront = TRUE)) %&gt;%
        addPolygons(data = bounds,
                    color = "red", 
                    weight = 2, 
                    fillOpacity = 0.1,
                    highlightOptions = highlightOptions(color = "black", 
                                                        weight = 2,
                                                        bringToFront = TRUE))
      ################################
      #Question 2
      ################################
  
    })
  
  }
  
  shinyApp(ui, server)
  </code></pre>