My map seems to be re-rendering when I use the select input options however it does not actually update the map with the inputs. My code is below...
library(shiny)
library(leaflet)
ui <- fluidPage(
selectInput(inputId = "select",
label = "Species",
choices = df$Species, multiple = TRUE),
leafletOutput("my_leaf")
)
server <- function(input, output, session){
df <- read.csv("C:\Users\Michael\Documents\TMMC\TMMC_EXCEL_R\PSM5\PatientStabilizationMap.csv", header=TRUE)
## create static element
output$my_leaf <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$Esri.NatGeoWorldMap, group = "Nat Geo World")%>%
addMarkers(data = df, lng= ~Lng, lat= ~Lat,clusterOptions = markerClusterOptions(),
popup= ~paste("<h3 style='color: blue'>Stranding Info</h3>","<b>Name:</b>",ï..Name,"<br>","<b>Field ID:</b>",Field.ID,"<br>","<b>Category:</b>",Category, sep=" ")
)
})
## filter data
df_filtered <- reactive({
df[df$Species >= input$select, ]
})
## respond to the filtered data
observe({
leafletProxy(mapId = "my_leaf", data = df_filtered()) %>%
clearMarkers() %>% ## clear previous markers
clearMarkerClusters()%>%
addMarkers(data = df, lng= ~Lng, lat= ~Lat,clusterOptions = markerClusterOptions(),
popup= ~paste("<h3 style='color: blue'>Stranding Info</h3>","<b>Name:</b>",ï..Name,"<br>","<b>Field ID:</b>",Field.ID,"<br>","<b>Category:</b>",Category, sep=" ")
)
})
}
shinyApp(ui, server)