For some reason, the pop-ups assigned to the polygons in the Shiny Brochure application are pulling out the wrong information that should be assigned to the polygon. It seems that the polygons were placed on the map and then the attributes of the polygon are assigned in a different order.
We will be very grateful for any ideas.
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! TO
source
share