I am trying to implement opening url in a new tab when a particular state in a map is clicked in rstudio leaflet.
I see in the below link which talks about how to open url in a new tab once you click on something. But I want to implement the same in RStudio leaflet. Please help.
Below is the map code. Let me know if you need anymore information.
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)
But I don't want the links on the popups. Once you click on the state, it should take me to the hyperlink. That is what I am looking for. If you have a sample code that would showcase where once you click on the state it will lead to the hyperlink. That would be great.
While what you describe is doable it would require a bit of custom js to handle the on click events & execute window.open(); so doable yes, but I don't have an example on hand right now.
leaflet has an onRender functionality for arbitrary javascript.
But I don't know much javascript nor the internal representation of the leaflet, so maybe ask on the github.