Prior to release 3.3-1 of {tmap}
(March 2021) you had less control over popups in tmap. The world has changed since, and you may consider this answer deprecated - using {leaflet}
directly still works, but it is no longer the only way to make hyperlinks work in popups.
For an example of a purely {tmap}
workflow please see my newer answer.
It is much easier to utilize leaflet library directly, via package leaflet
.
I first paste together the text of the popup as HTML and then use it in leaflet::addCircleMarkers()
calls as popup argument (the tilde is important).
The circle markers from leaflet are very much like tmap bubbles, and can be tuned to look much finer than this; for the sake of brevity of code I have concentrated on the main topic, i.e. customizable hyperlinks in popup balloons of an interactive map.
library(dplyr) # for mutate & pipe
library(tmap) # for the metro dataset
library(leaflet) # interface to leaflet
data("metro") # from the tmap package
metro %>%
mutate(label = paste("marvel at ", name, " and follow <a href = https://stackoverflow.com/>stack overflow</a>")) %>%
leaflet() %>%
addTiles(group = "OSM") %>%
addCircleMarkers(popup = ~label)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…