1

I would like to make a map of point locations using a tmap leaflet that when you click on a location it brings up a popup that includes a clickable link. Is there a way to do this?

Here is some sample code of what I would like to do:

library(sf)
library(tmap)

cities = data.frame(name=c("Pucón, Chile","Quito, Ecuador"),
                    altitude=c(227, 2850),
                    lon=c(-71.974444, -78.509722),
                    lat=c(-39.276667, -0.218611),
                    link1=c("https://fr.wikipedia.org/wiki/Puc%C3%B3n",
                                "https://fr.wikipedia.org/wiki/Quito"
                            ),
                    link2=c("https://www.lonelyplanet.com/chile/the-lakes-district/pucon",
                            "https://www.quito.gob.ec/"
                            )
)

cities = st_as_sf(cities,coords=c("lon","lat"),crs=4326)

lf = tmap_leaflet(tm_shape(cities)+tm_symbols(popup.vars = c("link1","link2")))

print(lf)

The leaflet will include the URLs in the popup, but they are not clickable. I have tried placing the URLs inside an html link (<a>), but that doesn't work.

Is there a solution to this problem?

user3004015
  • 617
  • 1
  • 7
  • 14
  • 2
    {tmap} sanitizes popup text for HTML code; you will have to use {leaflet} directly to achieve your aim. It is not difficult - consider the code in this earlier answer: https://stackoverflow.com/questions/55711438/is-there-a-way-to-make-hyperlinks-in-the-pop-up-of-a-tm-bubbles-item/55714484#55714484 – Jindra Lacko Feb 12 '20 at 07:16
  • Thanks! I was hoping there was another answer, but guess not. – user3004015 Feb 18 '20 at 12:47

0 Answers0