48 lines
1.1 KiB
R
48 lines
1.1 KiB
R
|
library("rvest")
|
||
|
library("dplyr")
|
||
|
|
||
|
url_page <-
|
||
|
"https://sauvetabouffe.org/boite-a-outils/repertoire-des-frigos-communautaires-du-quebec/"
|
||
|
selecteur_css <- "#tablepress-1"
|
||
|
|
||
|
html_page <- rvest::read_html(url_page)
|
||
|
|
||
|
frigo_table <-
|
||
|
html_page %>% rvest::html_element(selecteur_css) %>% html_table()
|
||
|
|
||
|
library(ggmap)
|
||
|
|
||
|
frigo_table2 <- frigo_table %>%
|
||
|
mutate(adr_propre = Adresse %>% str_remove("\\(.*\\)$") %>% str_trim())
|
||
|
|
||
|
register_google("AIzaSyDTU2aRAVXmt435qKjXnBM9NuvvQ0iRbiQ")
|
||
|
geo_frigo <- geocode(frigo_table2$adr_propre)
|
||
|
|
||
|
# Je patch celle qui n'a pas fonctionné
|
||
|
geo_frigo[4, ] <- list(-67.4330588, 48.4657985)
|
||
|
|
||
|
frigo_table3 <- frigo_table2 %>% cbind(geo_frigo)
|
||
|
|
||
|
frigo_table3 %>% write.csv("frigo_table.csv")
|
||
|
|
||
|
library(sf)
|
||
|
|
||
|
frigo_table_sf <- sf::st_as_sf(frigo_table3, coords = c("lon", "lat"))
|
||
|
|
||
|
frigo_table_sf %>% sf::write_sf("frigo_table_sf.geojson")
|
||
|
|
||
|
library(leaflet)
|
||
|
library(htmltools)
|
||
|
|
||
|
leaflet(data = frigo_table_sf) %>%
|
||
|
addTiles() %>%
|
||
|
addMarkers(popup = ~ paste0(
|
||
|
'<h2>',
|
||
|
Quoi,
|
||
|
'</h2><p>',
|
||
|
Adresse,
|
||
|
"</p>",
|
||
|
Particularités %>%
|
||
|
str_replace_all("\\n", "<br>")
|
||
|
))
|