Open URL in new TAB when we click on a state in a map

Opening links in new window is not a leaflet thing, but a HTML thing - you need to specify target=\"_blank\" in an anchor tag used in your popup argument.

I am sorry I don't quite follow the way your url is constructed and used (I can't see the <a> tag anywhere in your code) so excuse me when I use my own example.

It is based on my earlier answer on "the other site", with very minor changes.

library(dplyr)   # for mutate & pipe
library(tmap)    # for the metro dataset
library(leaflet) # interface to leaflet

data("metro") # from the tmap package

metro <- metro %>% 
  mutate(label = paste("marvel at ", name, " and follow <a href=\"https://forum.posit.co\", target=\"_blank\">RStudio Community</a>"))

leaflet(data = metro) %>%
  addTiles() %>%
  addCircleMarkers(popup = ~label)

1 Like