st_centroid_xy <- function(df) {
df |>
mutate(centroid = st_centroid(geometry),
x = sapply(centroid, "[[", 1),
y = sapply(centroid, "[[", 2)) |>
select(everything(),x,y,geometry,-centroid)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.