6

I want to add markers on a world map and when the user clicks in one marker, instead of a popup it would direct the user to another website.

I'm new to this library (actually it's the first one i've tried in order to solve this issue - an interactive map with hyperlinks markers for the user to click and go to another website), so all i could do was:

map <- leaflet() %>%
 addTiles()%>%
 addMarkers(lng=174.768, lat=-36.852, popup="https://www.r-project.org/")

Is there a way to do wha i want with leaflet in R? if not, can you suggest another library?

Thank you very much

mihasa
  • 967
  • 2
  • 10
  • 20

1 Answers1

7

Use HTML in the popup portion...

library("leaflet")
map <- leaflet() %>%
  addTiles()%>%
  addMarkers(lng=174.768, lat=-36.852, 
             popup='<a href="https://www.r-project.org/">R Project</a>')

Also, if you don't want to paste() your links together, the shiny library has functions for this...

shiny::a("something", href="www.something.com")
# <a href="www.something.com">something</a> 
cory
  • 6,529
  • 3
  • 21
  • 41
  • 2
    hi cory, thank you. This one works to hyperlink the text, so it's a possible solution (since i havent specified very well my question) so i've accepted as answer. But ideally, i would want the user to be directly redirected to the link on the marker on the click. I mean, i want to avoid the popup, so user wouldnt have to click on marker to see a pop up and then click on link, but instead just click on the marker and, w/out a pop up, be redirected to link. do you know if that's possible? – mihasa Apr 04 '16 at 20:41
  • mihasa did you find an answer to this? I'd like the same functionality, and have gone about it via @cory's approach. Today I saw [this example -- see "Interactive Charts" section](http://dcenergy.github.io/rflot/), which makes me think that maybe it's possible. – Rich Pauloo Oct 02 '19 at 23:35