library(rgdal)
## Loading required package: sp
## rgdal: version: 1.3-4, (SVN revision 766)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.1.2, released 2016/10/24
##  Path to GDAL shared files: /usr/share/gdal/2.1
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
##  Path to PROJ.4 shared files: (autodetected)
##  Linking to sp version: 1.3-1
library(leaflet)

shp<-readOGR("data","constituencies_new")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/rstudio/webpages/ukelections/data", layer: "constituencies_new"
## with 632 features
## It has 10 fields
## Integer64 fields read as strings:  cartodb_id
#str(shp@data)
d<-read.csv("data/combined.csv")
#str(d)
shp<-merge(shp,d,by.x="gss",by.y="id")
#str(shp@data)

shp<-shp[!is.na(shp$Win),]


cls<-colorFactor(c('blue', 'green', 'red', 'orange', 'pink', 'purple'),domain = shp$Win)
mp<-leaflet(shp) %>%
  addTiles() %>%
addPolygons(fillColor = cls(shp$Win),color=cls(shp$Win))
mp
#writeOGR(shp,"data","resultseng","ESRI Shapefile",over=TRUE)
carto<-readOGR("data","cartogram")
## OGR data source with driver: ESRI Shapefile 
## Source: "/home/rstudio/webpages/ukelections/data", layer: "cartogram"
## with 573 features
## It has 35 fields
## Integer64 fields read as strings:  crtdb_d Con Green Lab LibDem Plaid SNP UKIP ttl_vts SNP_p under18 under40 over40 ttl_vtr hs_1996 hs_2013
mp<-leaflet(carto) %>%
addPolygons(fillColor = cls(shp$Win),color=cls(shp$Win))
mp
dd<-carto@data