I have a code that allows me to change tile layers using a booklet and a brilliant one for R. When I try to add Circles using the addCircle flyer function, circles do not appear on the map displayed. There is no mistake if the circles just don't appear anymore. I would like to be able to add the same circles to all layers of a tile when I modulate them. I added the ui and server code. Thank you so much for your help.
ui.R:
library(shiny);library(leaflet)
shinyUI(navbarPage("Switch Map",
tabPanel("Map",
div(class="outer",tags$head(includeCSS("styles.css")),
htmlOutput("mapp",inline=TRUE)),
absolutePanel(top = 60, left = "auto", right = 20, bottom = "auto",
selectInput("mapPick", "Background Map",c("OpenStreetMap" = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
"MapQuestOpen.Aerial"= "http://oatile3.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg"),
selected = c("http://oatile3.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg"))))))
server.R:
library(shiny);library(leaflet)
shinyServer(function(input, output, session) {
output$map1 <- reactive(TRUE)
map1 <- createLeafletMap(session, "map")
output$mapp <- renderUI({
input$mapPick
isolate({
leafletMap("map", "100%", "100%",
initialTileLayer = input$mapPick,
initialTileLayerAttribution = HTML('Fix This Later'),
options=list(center = center(),zoom = zoom()))
})
})
zoom <- reactive({
ifelse(is.null(input$map_zoom),5,input$map_zoom)
})
center <- reactive({
if(is.null(input$map_bounds)) {
c(40, -98.85)
} else {
map_bounds <- input$map_bounds
c((map_bounds$north + map_bounds$south)/2.0,(map_bounds$east + map_bounds$west)/2.0)
}
})
session$onFlushed(once=TRUE, function() {
paintObs <- observe({
sizeBy <- input$size
clinicData<-clinicDataReactive()
colorData<-clinicData$Facility.Type
colors <- brewer.pal(3,"Set1")[cut(colorData, 3, labels = FALSE)]
map$clearShapes()
chunksize <- 1000
for (from in seq.int(1, nrow(clinicData), chunksize)) {
to <- min(nrow(clinicData), from + chunksize)
zipchunk <- clinicData[from:to,]
try(
map$addCircle(
zipchunk$latitude, zipchunk$longitude,
(zipchunk[[sizeBy]] / max(clinicData[[sizeBy]]))*5000,
zipchunk$Index,
list(stroke=FALSE, fill=TRUE, fillOpacity=0.4),
list(color = colors[from:to])
)
)
}
})
session$onSessionEnded(paintObs$suspend)
})
})