R/leafletでラベルのテキストを改行


labelはマウスオーバができて、popupはマウスオーバができなさそうなので。

library(leaflet)
library(stringi)
library(htmltools)

name <- stri_rand_strings(n=10, length=8)
lat <- rnorm(n=10, mean=35, sd=1)
lng <- rnorm(n=10, mean=135, sd=1)
X <- data.frame(name, lat, lng)
X$text <- paste(
  "Name: ", X$name, "<br>",
  "Latitude: ", round(X$lat, 3), "<br>",
  "Longitude: ", round(X$lng, 3), "<br>",
  sep=""
)

# Before
leaflet() %>%
  addTiles() %>%
  addCircleMarkers(lng=X$lng, lat=X$lat, label=X$text)

# After
leaflet() %>%
  addTiles() %>%
  addCircleMarkers(lng=X$lng, lat=X$lat, label=lapply(X$text, HTML)

Before

After