While trying to show more than one line by the method posted by einar, I couldn't show both of them at once. After much digging, I came across this and this posts. Here is a small code for two different lines.
library(geosphere)
library(leaflet)
library(dplyr)
lat_ny <- 40.73
lng_ny <- -73.9
lat_del <- 28.63
lng_del <- 77.21
lng_ca <- -121.6406
lat_ca <- 39.16414
inter1 <- gcIntermediate(c(lng_ny, lat_ny), c(lng_del, lat_del), n=10, addStartEnd=TRUE, sp = TRUE, breakAtDateLine = TRUE)
lines(inter1)
inter2 <- gcIntermediate(c(lng_ca, lat_ca), c(lng_del, lat_del), n=10, addStartEnd=TRUE, sp = TRUE, breakAtDateLine = TRUE)
lines(inter2)
inters <- c(inter1,inter2)
ll0 <- lapply( inters , function(x) `@`(x , "lines") )
ll1 <- lapply( unlist( ll0 ) , function(y) `@`(y,"Lines") )
Sl <- SpatialLines( list( Lines( unlist( ll1 ) , ID = 1 ) ) )
leaflet(Sl) %>% addTiles() %>% addPolylines()
Hardcoding latitude and longitude is not a good idea, but as I had to pick only top 5 connect place, I did not devote much time for indexing of a list. Also I am still to check if it integrates with Shiny.
