我的传单地图上的标签在悬停时显示了错误的州/地区名称。在下面的代码中,我将根据用户选择的输入连接两个数据集-形状文件和数据文件的子集。该加入的文件被馈送到地图的传单中。
我仅在绘制形状文件时检查,标签显示正确的地理位置,但是当形状文件与数据文件保持连接时,标签指向错误的地理位置。
我还获取了新加入的数据框的excel输出,它在匹配方面看起来是正确的,但是在地图上却被弄乱了。
这可能是什么原因?
我没有提供可重复的示例,因为问题可能出在我的数据集中。虽然我不太确定。
server <- function(input, output, session) {
subsetData <- reactive({
if (input$vote =="All"|input$vote =="NA"){
df <- aishe_m %>%
filter(variable == input$indicator) %>%
filter(Year == input$year)
}
else{
df <- aishe_m %>%
filter(variable == input$indicator) %>%
filter(Year == input$year) %>%
filter(`leading party` == input$vote)
}
return(df)
})
lat = 20.899071
lng = 85.8007
zoom = 5
observe({
shape@data <- left_join(shape@data, as.data.frame(subsetData()), by = c("censuscode", "st_code"))
View(shape@data)
write_xlsx(shape@data, "/Users/shreyaagarwal/Desktop/shapefilenew.xlsx")
qpal <- colorQuantile("YlOrRd", shape@data$value, n = 4, na.color = "#bdbdbd")
leafletProxy("aishe_map") %>%
clearShapes() %>%
addPolygons(data = shape, fillColor = ~qpal(value), fillOpacity = 0.9, color = "white", weight = 2,
label = as.character(shape$State),
highlightOptions = highlightOptions(color = "yellow",
weight = 5,
bringToFront = TRUE))
})
qpal <- colorQuantile("YlOrRd", shape@data$value, n = 4, na.color = "#bdbdbd")
output$aishe_map <- renderLeaflet({
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
setMaxBounds(lng1 = 90, lat1 = 18, lng2=75, lat2=22) %>%
setView(lat = lat, lng = lng, zoom = zoom) %>%
addLegend(position = "topright", pal = qpal, title = input$indicator, values = subsetData()$value, opacity = 0.7)
})
}
# Run the application
shinyApp(ui = ui, server = server)