Sort drop down menu and remove dependencies

This commit is contained in:
2025-12-08 19:44:19 +01:00
parent 218567f28e
commit 9c9866b9af

View File

@@ -5,8 +5,6 @@ library(leaflet)
library(sf) library(sf)
library(htmltools) library(htmltools)
library(dplyr) library(dplyr)
library(tidyr)
library(purrr)
# Json of Crime Reports # Json of Crime Reports
crime_json <- fromJSON(file="data.json") crime_json <- fromJSON(file="data.json")
@@ -24,8 +22,8 @@ map_data_to_table <- function(bezirk, stadtteil, year) {
tibble( tibble(
Name = crime, Name = crime,
`Erfasste Fälle` = row[["Erfasste Fälle"]], `Erfasste Fälle` = as.integer(row[["Erfasste Fälle"]]),
`Aufgeklärte Fälle` = row[["Aufgeklärte Fälle"]], `Aufgeklärte Fälle` = as.integer(row[["Aufgeklärte Fälle"]]),
`Aufklärung relativ` = row[["Aufklärung relativ"]] `Aufklärung relativ` = row[["Aufklärung relativ"]]
) )
}) })
@@ -40,7 +38,7 @@ geo_bezirke$leaflet_id <- paste("bez_", geo_bezirke$bezirk, sep="")
geo_stadtteile <- st_read("geostadtteile-parsed.json") geo_stadtteile <- st_read("geostadtteile-parsed.json")
geo_stadtteile <- st_transform(geo_stadtteile, crs = 4326) geo_stadtteile <- st_transform(geo_stadtteile, crs = 4326)
geo_stadtteile$leaflet_id <- paste("std_", geo_stadtteile$stadtteil, sep="") geo_stadtteile$leaflet_id <- paste("std_", geo_stadtteile$stadtteil, sep="")
bezirke <- names(crime_json) bezirke <- sort(names(crime_json))
#User interface definitions #User interface definitions
@@ -54,8 +52,8 @@ ui <- function() {
textOutput("txt_map_selection_stadtteil"), textOutput("txt_map_selection_stadtteil"),
"2024", "2024",
tableOutput("tbl_2024"), tableOutput("tbl_2024"),
"2023", #"2023",
tableOutput("tbl_2023"), #tableOutput("tbl_2023"),
), ),
col_widths = c(7, 5), col_widths = c(7, 5),
), ),
@@ -110,14 +108,14 @@ update_selection_table <- function(output) {
), ),
striped = TRUE striped = TRUE
) )
output$tbl_2023 <- renderTable( # output$tbl_2023 <- renderTable(
map_data_to_table( # map_data_to_table(
bezirk = currently_selected_bezirk, # bezirk = currently_selected_bezirk,
stadtteil = currently_selected_stadtteil, # stadtteil = currently_selected_stadtteil,
year = "2023" # year = "2023"
), # ),
striped = TRUE # striped = TRUE
) # )
} }
#Server handling user input and processing of data #Server handling user input and processing of data
@@ -128,6 +126,7 @@ server <- function(input, output, session){
if (sel_bezirk != "") { if (sel_bezirk != "") {
sel_stadtteile <- names(crime_json[[sel_bezirk]]) sel_stadtteile <- names(crime_json[[sel_bezirk]])
selected_stadtteil <- paste("Bezirk", sel_bezirk)
updateSelectInput( updateSelectInput(
session, session,
inputId = "drp_stadtteil", inputId = "drp_stadtteil",