Reputation: 11
I hav a map where all the zipcodes are clickable. Whenever I click on a specific zipcode area I get a popup, this popup will show the name and grade of a school. My problem now is, that there are more than 1 schools on 1 zipcode and I want to show all schools of each zipcode in the popup.
shape_and_data <- merge(zipcode, aantal_hyp, by.x="PC4", by.y="ZIPCODE_SCHOOL", duplicateGeoms=TRUE, multiple = TRUE)
#way to make colorpalletes
pal <- colorQuantile("YlGn", NULL, n = 5)
state_popup <- paste0("<strong>Schoolnaam: </strong>",
shape_and_data$INSTELLINGSNAAM_VESTIGING,
"<br><strong>Quasi cito : </strong>",
shape_and_data$quasicito)
leaflet(data = shape_and_data) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = ~pal(GEMEENTENUMMER),
fillOpacity = 0.8,
color = "#BDBDC3",
weight = 1,
popup = state_popup)
The area with state_popup <- paste0("<strong>Schoolnaam: </strong>",
is the popup, as you can see it will only print out 1 schoolname.
Upvotes: 1
Views: 164
Reputation: 209
Try referencing the variables inside your leaflet() call:
leaflet(data = shape_and_data) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(fillColor = ~pal(GEMEENTENUMMER),
fillOpacity = 0.8,
color = "#BDBDC3",
weight = 1,
popup = paste("<strong>Schoolnaam: </strong>",
shape_and_data$INSTELLINGSNAAM_VESTIGING,
"<br><strong>Quasi cito : </strong>",
shape_and_data$quasicito))
Upvotes: 1