I am using RStudio to create a choropleth leaflet map. I have Country and Url as an attribute in the shapefile that I imported to R.
I wish to show the Country name and URL as a hyperlink within the popup of the final map.
Below is the code I have used so far:
m <- world_shapefiles %>%
leaflet() %>%
addProviderTiles(providers$Esri.WorldStreetMap) %>%
addPolygons(
label=~country,
labelOptions = labelOptions(style = list("font-weight" = "normal", padding = "3px 8px", textsize = "15px",
direction = "auto")),
popup = ~ paste("Country:", country, "<br/>","<b/>","URL:", url)
)
I want to see the text "Click here" instead of the entire url in the popup, I tried using the below code with no luck.
popup = ~ paste("Country:", counry, "<br/>","<b/>","URL:", "<b><a href=url>Click Here</a></b>")
Any ideas to achieve it?
Overview
After reading R, leaflet package, Passing a character vector of HTML tags to popups?, here's how you would modify your existing code:
Reproducible Example
I use the World Borders Data Set to download shapefiles for each country in the world. I then add a Wikipedia URL for each country in the data set.