library(knitr)
library(DT)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Loading the package and looking at prepared data

We start by loading tidyverse package to manipulate with data and then load the package itself.

library(tidyverse)
library(sf)
library(CzechData)
library(leaflet)
library(RColorBrewer)
library(htmlwidgets)
library(rmapshaper)
data(obce)
data(okresy)
id_okresy_Brno <- okresy %>% 
  filter(str_detect(nazev, "Brno")) %>% 
  pull(lau1_kod)

obce_obce <- obce %>% 
  filter(lau1_kod %in% id_okresy_Brno) %>% 
  datatable(options = list(scrollX = TRUE))

# saveWidget(obce_obce, file = "tabulka.html", selfcontained = FALSE)
id_obec <- obce %>% 
  filter(nazev == "Brno") %>% 
  pull(kod)
volebni_okrsky <- load_RUIAN_settlement(id_obec, layer = "volebni okrsky")

volebni_okrsky <- volebni_okrsky %>% 
  select(cislo) %>% 
  st_transform(4326) 

volebni_okrsky <- ms_simplify(volebni_okrsky, keep = 0.1)

names(st_geometry(volebni_okrsky)) <- NULL
labels <- sprintf("<strong>%s</strong>", volebni_okrsky$cislo) %>% 
  lapply(htmltools::HTML)

l <- leaflet(data = volebni_okrsky, width = "100%") %>%
  addTiles() %>%
  addPolygons(fillColor = brewer.pal(8, "Set2"), fillOpacity = 0.4,
              stroke = TRUE, weight = 0.5, color = "black",
              highlight = highlightOptions(weight = 3,
                                           bringToFront = TRUE),
              label = labels)

# saveWidget(l, file = "mapa.html", selfcontained = FALSE)


JanCaha/CzechData documentation built on Dec. 25, 2021, 1:49 p.m.