Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[R][Leaflet]: hyperlink on click

Tags:

r

leaflet

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

like image 916
mihasa Avatar asked Mar 29 '16 19:03

mihasa


Video Answer


1 Answers

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> 
like image 145
cory Avatar answered Oct 14 '22 19:10

cory