Defibrillator from OSM

[This article was first published on, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A photo of flowers in the shape of hearts

Bleeding Heart – CC-BY by Theo Crazzolara

Day 15 of 30DayMapChallenge: « OpenStreetMap » (previously).

Using data from OSM we’ll make a web map of defibrillators (AED) in Auvergne-Rhône-Alpes.


We send an Overpass API query with {osmdata}:

# France regions
# See for the data
fr <- read_sf("~/data/adminexpress/adminexpress_cog_simpl_000_2022.gpkg", layer = "region") |> 
  filter(insee_reg > "06")

# Get and cache OSM data for France
if (!file.exists("aed.rds")) {
  aed <- opq(st_bbox(fr), osm_types = "node", timeout = 6000) |>
    add_osm_features(features = c(
      '"emergency"="defibrillator"')) |> 
    osmdata_sf() |> 
    pluck("osm_points") |> 
    st_join(fr, left = FALSE) |> 
} else {
  aed <- read_rds("aed.rds")

Automated external defibrillator in AURA

icons <- awesomeIcons(
  library = "fa",
  icon = "heart",
  markerColor = "white",
  iconColor = "darkgreen")

# Just keep the region data
aed |> 
  st_join(fr |> 
            filter(insee_reg == 84),
          left = FALSE) |> 
  leaflet(options = leafletOptions(preferCanvas = TRUE)) |> 
  addTiles() |> 
    clusterOptions = markerClusterOptions(),
    icon = icons,
    popup = ~glue("
      <tr><th style='font-weight:bold'>localisation</th>
          <td>{htmlEscape(coalesce(`defibrillator:location:fr`, `defibrillator:location`))}</td></tr>
      <tr><th>intérieur</th><td>{htmlEscape(coalesce(indoor, `indoor:description`))}</td></tr>
      <tr><th>description</th><td>{htmlEscape(coalesce(`description:fr`, description))}</td></tr>
To leave a comment for the author, please follow the link and comment on their blog: offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)