This is actually a pretty common use case, and a while back I wrote a blogpost about this (and other leaflet.js tricks in R). You might find it interesting - https://www.jla-data.net/eng/leaflet-in-r-tips-and-tricks/
But in case you are just after the TLDR solution: consider the following code
- it first creates a valid HTML column based on your URL
- then it uses this HTML for popup while constructing the marker
I hope this helps...
library(dplyr)
library(sf)
# Create tibble
dat <- tibble(site = c("loc_1", "loc_2", "loc_3"),
url_1 = c("https://community.rstudio.com/",
"https://cran.r-project.org/",
"https://rstudio.github.io/leaflet/"),
coord_x = c(1, 4, 8),
coord_y = c(3, 2, 6))
# Convert to sf
dat_sf <- st_as_sf(dat, coords = c("coord_x", "coord_y"))
# turn the url to HTML anchor tag
dat_sf <- dat_sf %>%
mutate(tag = paste0("lookie: <a href=", url_1,">", url_1, "</a>"))
# draw the map using {leaflet}
library(leaflet)
leaflet(dat_sf) %>%
addProviderTiles("CartoDB.Positron") %>% # or some other...
addCircleMarkers(popup = ~tag, # note the tilde notation!
opacity = .75,
stroke = NA)