Helle everybody
I want to colour pologyons i'm displaying on a leaflet map with shiny, using calculated datas.
I don't really understand the option in the leaflet function addPolygon and how can use it to render my polygons.
It's rendering me all the polygon with default color
Here's a chunck
My ploygon is named poly
#Variable to represent : var_deb
var_deb <- as.vector(poly[,5])
# Number of classes
nbclass <- 11
# Intervals
distr <- c(-500,-250,-100,-75,-50,-25,-5,0,5,25,50,75,100,250,500)
# Colors
colours <- brewer.pal(nbclass, "RdBu")
colMap <- colours[(findInterval(var_deb, distr, all.inside = TRUE))]
#Option to pass to addPolygon
opts=list(fillColor=colMap[1])
for (i in 2:length(colMap))
{
opt=NA
opt=list(fillColor=colMap[i])
opts=c(opts,opt)
}
map$addPolygon(lat=poly[,2],lng=poly[,1],layerId=poly[,3],options=opts)
Does someone has an idea ?
Thks
Fabien