0

I have a table in which one of the columns is website urls, how do I add hyperlink with these urls in a popup in leaflet? here is my code:

content <- paste(sep = "\n",
                    my_table$names,
                    my_table$websites)
my_map <- leaflet(my_table) %>%
  setView(lng = -98.583, lat = 39.833, zoom = 4) %>% 
  addTiles() %>% 
  addProviderTiles(providers$Wikimedia) %>% 
  addMarkers(
    clusterOptions = markerClusterOptions(),
    popup = htmlEscape(content),
    icon = my_icon
  )
IvanSanchez
  • 18,272
  • 3
  • 30
  • 45

1 Answers1

1

I changed the way you are calling the content object a bit to paste the html code for creating a hyperlink, with quotes, around the columns in your dataframe.

    content <- yourDataframe %>% 
    mutate(popup = paste0('<a href =', websites, '>', names, '</a>'))

    my_map <- leaflet(my_table) %>%
    setView(lng = -98.583, lat = 39.833, zoom = 4) %>% 
    addTiles() %>% 
    addProviderTiles(providers$Wikimedia) %>%
    addMarkers(lng = content $longitude, 
         lat = content $latitude,
         clusterOptions = markerClusterOptions(),
         popup = content$popup)

enter image description here

Susan Switzer
  • 1,531
  • 8
  • 34