I'm trying to add different icon to the markers which I'm trying to show. I have different category like this
category <- data() %>%
dplyr::select(category) %>%
distinct()
and it looks something like this
$ category: chr "Traffic" "Livelihood" "Waste" ....
I have a variable for logos for choosing different icon for the category
logos <- awesomeIconList(
"Pothole" = makeAwesomeIcon(
icon = "road",
markerColor = "black"
),
"Garbage Collection" = makeAwesomeIcon(
icon = "trash",
markerColor = "green"
),
"Air Quality" = makeAwesomeIcon(
icon = "cloud",
markerColor = "blue"
)
)
and I have written logic in observe function which I separated from the main logic and I don't why this is not working for me. This was working when I was not using observe function and was not using leaflet proxy. When I was using it in the renderLeaflet function then it was working.
I don't know what can I do here and from the error I didn't understand much about the logic
observe({
filtered_data <- bqdata() %>%
dplyr::filter(
if ("All" %in% input$category) {
category != ""
} else {
category %in% input$category
}
)
proxy <- leafletProxy("layer_data")
if (input$cluster) {
proxy %>% addAwesomeMarkers(
lat = filtered_data$lat,
icon = ~logos[category],
lng = filtered_data$long,
popup = paste0(
"<b>Title: </b>", filtered_data$title, "<br>",
"<b>Type: </b>", filtered_data$type, "<br>",
"<b>Category: </b>", filtered_data$category, "<br>",
"<b>Status: </b>", filtered_data$status, "<br>",
"<b>Description: </b>", filtered_data$description, "<br>",
"<b>Address: </b>", filtered_data$address, "<br>",
"<b>City Name: </b>", filtered_data$city, "<br>",
"<b>State Name: </b>", filtered_data$state, "<br>"
),
clusterOptions = markerClusterOptions()
)
} else {
proxy %>% clearMarkerClusters()
}
})
icon = logos[filtered_data$category]
, I don't think you need the ~.