Add Section click detection

This commit is contained in:
2025-12-07 17:24:56 +01:00
parent e7ae8eb557
commit 6e0ad2ab30

View File

@@ -9,9 +9,12 @@ crime_json <- fromJSON(file="data.json")
geo_bezirke <- st_read("geobezirke-parsed.json")
geo_bezirke <- st_transform(geo_bezirke, crs = 4326)
geo_bezirke$leaflet_id <- paste("bez_", geo_bezirke$bezirk, sep="")
geo_stadtteile <- st_read("geostadtteile-parsed.json")
geo_stadtteile <- st_transform(geo_stadtteile, crs = 4326)
geo_stadtteile$leaflet_id <- paste("std_", geo_stadtteile$stadtteil, sep="")
bezirke <- names(crime_json)
@@ -35,7 +38,9 @@ ui <- page_fillable(
)
),
leafletOutput("hhmap"),
card("Card rechts"),
card(
textOutput("txt_map_selection")
),
col_widths = c(3, 6, 3)
)
)
@@ -75,11 +80,26 @@ server <- function(input, output, session){
}
})
observeEvent(input$hhmap_shape_click, {
click_event <- input$hhmap_shape_click
# Check if an ID was returned (meaning a polygon was clicked)
if (!is.null(click_event$id)) {
# The ID of the clicked polygon
clicked_polygon_id <- click_event$id
output$txt_map_selection <- renderText({
clicked_polygon_id
})
print(paste("Polygon with ID", clicked_polygon_id, "was clicked."))
}
})
output$hhmap <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(
data = geo_bezirke,
layerId = ~leaflet_id,
group = "layer_bezirke",
color = "#7bb5ab",
fillColor = "#bdf0e7",
@@ -94,6 +114,7 @@ server <- function(input, output, session){
addPolygons(
data = geo_stadtteile,
group = "layer_stadtteile",
layerId = ~leaflet_id,
color = "#7bb5ab",
fillColor = "#bdf0e7",
options = pathOptions(pane = "overlayPane"), # Use a leaflet option to ensure it's hidden