For some reason, the popups assigned to the polygons on the Shiny leaflet app are pulling up the wrong information that should be assigned to the polygon. It seems that the Polygons have been placed on the map, then assigned the polygon attributes in a different order.
Any ideas would be greatly appreciated.
server<-function(input,output,session)({
output$map<-renderLeaflet({
leaflet() %>%
addTiles() %>%
addPolygons(data = spatial_merge,
layerId = spatial_merge@data$PolygonNo,
stroke= TRUE, fillOpacity = 0.5, smoothFactor = 0.5, weight=1,
color = "grey", opacity = 1, popup=paste(sep= "<br/>",
"<b>ForestName: </b>", spatial_merge$ForestName,
"<b>Project Name: </b>", spatial_merge$Project_Name,
"<b>Treatment Year: </b>", spatial_merge$Project_Year,
"<b>Treatment Type: </b>", spatial_merge$Treatment_Type,
"<b>Area Treated: </b>", spatial_merge$Polygon_Area,
"<b>Polygon Cost: </b>", spatial_merge$TotalCost,
"<b>Contractor Name: </b>", spatial_merge$Project_Contractor)
})
})
shinyApp(ui,server)
> class(spatial_merge)
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"
> names(spatial_merge)
[1] "Primary_Key" "Project_Name" "PolygonNo" "WMA" "ContractName" "Project_Year"
[7] "Treatment_Type" "Project_Contractor" "Polygon_Area" "TotalCost" "OBJECTID_12" "FA_NAME"
[13] "Comments" "Source" "DataCaptureDate" "DataCapturedBy" "Block_ID" "SubBlock_ID"
[19] "SHAPE_Length" "SHAPE_Area"
> dim(spatial_merge)
[1] 647 20
Thanks for looking at my question! K