c0bra
c0bra

Reputation: 1080

How to display html labels in leaflet for R?

the leaflet for R manual states, that labels can be simple text as well as html text. However, if I try to add html to a label, it is not formatted as such:

leaflet(data=tibble(latitude=41.3828939, longitude=2.1774322, label="<b>TEXT</b>")) %>% 
  addTiles() %>% 
  addMarkers(label=~label)

map screenshot

Any advice is appreciated. Thanks.

Upvotes: 1

Views: 338

Answers (1)

s__
s__

Reputation: 9485

You can try something like this:

library(leaflet)
library(tibble)
library(htmltools)

leaflet(data=tibble(latitude = 41.3828939,
                    longitude= 2.1774322,
                    label    = HTML("<b>TEXT<br> text</b>"))) %>% 
  addTiles() %>% 
  addMarkers(label=~label)

enter image description here

Upvotes: 2

Related Questions