Here is the final script from the end of the tutorial video above. Following this will be a demonstration of including hyperlinks in your popup windows.
# load leaflet library
library(leaflet)
# Set up your data frame
data <- data.frame(c(43.11940,43.11940),
c(-79.24658,-79.244658),
c("HQ 1","HQ 2"),
c(4736583,3204853),
c('',
''))
# give names to your data columns
names(data) <- c("lat","lng","name","score","video")
# create the leaflet map variable
m <- leaflet() %>%
addProviderTiles("Esri.WorldTopoMap") %>%
addMarkers(data=data,
lat=~lat,
lng=~lng,
popup= ~paste("Hello World
","Name:",name,"
","Score:",score, video, sep=" ")
)
# print map
m
There are plenty of ways to go about doing this in the leaflet package, but I will outline two here.
<a href="url">link text</a>paste() function in R we will use a link to the GeomaTECHs YouTube channel: https://www.youtube.com/channel/UCTalI0S14Ek6DcvvvFIFPOg.# create the leaflet map variable
m <- leaflet() %>%
addProviderTiles("Esri.WorldTopoMap") %>%
addMarkers(data=data,
lat=~lat,
lng=~lng,
popup= ~paste("Hello World
","Name:",name,"
","Score:",score, video,
"
","Link:","GeomaTECHs YT Channel",sep=" ")
)
# print map
m
data variable that was created.
First create a list of the links you would like to add to your data frame. This step will only need to be done if you are creating your data from scratch or if you need to combine an existing dataset with a set of hyperlinks. If it is the latter, then be sure the list of hyperlinks is as long as the length of the columns in your origional data or you may have problems.
Okay lets create the list of hyperlinks:
# create list of links in a variable
links.list <- c("GeomaTECHs YT Channel",
"GeomaTECHs Tutorial")
Now we can add a link colummn to our data variable using the data$link.
data$link <- links.list
The final step is to add the variable link to the paste() function. In this example I have placed the link under the YouTube videos.
# create the leaflet map variable
m <- leaflet() %>%
addProviderTiles("Esri.WorldTopoMap") %>%
addMarkers(
data=data,
lat=~lat,
lng=~lng,
popup= ~paste("Hello World
","Name:",name,"
","Score:",score, video,link,sep=" ")
)
# print the map
m
For every tutorial video on YouTube I will try and use this Steemit account to expand on any complicated questions that viewers may have. As more questions come in I will add information to these documents hopefully answering them. So be sure to keep checking back for new information.