Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can leaflet pop-up labels be formatted in R?

I have a dataframe:

https://www.dropbox.com/s/51j3hh9urwjudu2/Agents.csv?dl=0

Using this, I can create a leaflet map using this code:

map = leaflet() %>%

  addTiles() %>%  # Add default OpenStreetMap map tiles

  addCircles(lng = agents$longitude, lat = agents$latitude, 
             popup=paste("Agent:", agents$Agent, "<br>",
                         "Satisfaction:", agents$Satisfaction, "<br>", 
                         "No. Customers:", agents$Customers, "<br>",
                         "Colour Ref:", agents$Colour), 
             radius = agents$Customers * 10,
             color = agents$Colour,
             stroke = FALSE, fillOpacity = 0.5)

which looks like this:

enter image description here

Now, I would like to:

have the first line in bold font (in this case 'Agent 4'). I have tried inserting:

"", agents$Agent, font = 2 "<br>",

but this does not work.

I would also like to tab 'Medium', '4200' and 'green' so that they are all in line with each other and so easier to read.

Does anyone know how to do this? Thank you!

like image 331
AJGL Avatar asked Nov 29 '17 17:11

AJGL


1 Answers

I find it easier to create a new variable in the data frame for the popup text.

Here is an example.

agents$popup_text <- 
  paste0('<strong>', agents$Agent, '</strong>',
         '<br/>', 'Satisfaction: ', '<strong>', agents$Satisfaction, '</strong>', ' ') %>% 
  lapply(htmltools::HTML)
like image 153
Samuel Avatar answered Oct 13 '22 05:10

Samuel