Coloring polygons with Data using leaflet in shiny

1,012 views
Skip to first unread message

Fabien Rinaldi

unread,
Jul 10, 2014, 11:22:48 AM7/10/14
to shiny-...@googlegroups.com
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





Franco Peschiera

unread,
Jul 10, 2014, 11:34:17 AM7/10/14
to Fabien Rinaldi, shiny-...@googlegroups.com
Hello Fabien,

Check this entry: it has an example with addPolygon:
https://groups.google.com/forum/#!msg/shiny-discuss/JkJfLA2l8lQ/V-1k0AtXjcAJ

also check this example that comes with leaflet-shiny package:
https://github.com/jcheng5/leaflet-shiny/tree/master/inst/examples/choropleth

 .

--
Sent from my netBook


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages