AIM
Create a leaflet map using Shiny that represents one set of data with circle marker and add a markers for points using a second set of data.
ISSUE The "circle" markers are working, but "markers" are not. The "addMarkers" code is not being read or is being ignored.
SERVER
library(shiny)
library(leaflet)
server <- function(input, output, session) {
points <- read.csv(textConnection("Loc,STZip,Lat,Long,Vol
Loc1,17699,40.0185,-76.297582,15
Loc2,76177,32.949819,-97.31406,20
Loc3,27801,35.935125,-77.77076,17
Loc4,52404,41.947335,-91.68819,12
Loc5,19380,39.983108,-75.59332,18
"))
newpoints <- read.csv(textConnection("Loc,STZip,Lat,Long,Vol
Loc6,18640,41.317242,-75.77942,12
Loc7,38133,35.208709,-89.80518,20
"))
output$mymap <- renderLeaflet({
leaflet() %>%
addProviderTiles("Stamen.TonerLite",
options = providerTileOptions(noWrap = TRUE)) %>%
addCircleMarkers(lng = ~Long, lat = ~Lat, radius = ~Vol, layerId = NULL,
group = "NGS_Facilities", stroke = TRUE, color = "#0000CC", weight = 5, opacity = 0.5,
fill = TRUE, fillColor = "#0000CC", fillOpacity = 0.2, dashArray = NULL,
popup = ~Loc, options = pathOptions(), clusterOptions = NULL, clusterId = NULL,
data = (newpoints)) %>%
#this code is not being read or is ignored...
addMarkers(lng = ~Long, lat = ~Lat, popup = ~Loc, data = (newpoints))
})
}
UI
library(shiny) library(leaflet)
r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()
ui <- fluidPage(
title = "Map of Stuff",
leafletOutput("mymap", width = 1800, height = 800),
p()
)