更新
当我注释掉弹出代码时,重复项就消失了……
当我在walk()函数内部的弹出窗口中添加所需信息时,无需重复即可得到所需的内容,因此我想它是使用分配的Popup
并通过无论记录存在多少次,每次循环都会在一个点上永远循环。
下面有我从R-Studio的传单站点改编的以下代码,唯一不同的是我的数据。
例如,我有一条Bariatrics服务线,该服务线只能在地图上映射四(4)个标记,而在地图上却可以得到657个标记。
有什么尖叫吗?
# Popup Code
Popup <- paste(
"Hospitalist/Private:"
, joined_data$Hospitalist_Private
, "Address: "
, joined_data$FullAddress
, "Service Line: "
, joined_data$LIHN_Line
, "Readmit: "
, joined_data$Readmit_Count
, "SOI: "
, joined_data$SOI
, "Encounter: "
, joined_data$PtNo_Num
, "Payer Group: "
, joined_data$Payor_Category
)
# Makes 19 data.frames
LIHNCluster.df <- split(joined_data, joined_data$LIHN_Line)
# Create the initial map object
ClusterMapLIHN <- leaflet() %>%
setView(lng = sv_lng, lat = sv_lat, zoom = sv_zoom) %>%
addTiles() %>%
addTiles(group = "OSM (default)") %>%
addProviderTiles("CartoDB.Positron") %>%
addControl(
paste("LIHN Service Line Cluster Map for:", MaxRptMonth, MaxRptYr)
, position = "topright"
)
# Use purrr::walk to loop through the LIHNCluster.df and add
# markers to the map
names(LIHNCluster.df) %>%
purrr::walk( function(df) {
ClusterMapLIHN <<- ClusterMapLIHN %>%
addMarkers(
data = LIHNCluster.df[[df]]
, lng = ~LON
, lat = ~LAT
, label = ~as.character(LIHN_Line)
#, popup = ~as.character(Popup)
# When I do the following I get the info I want without duplication
, popup = ~as.character(
paste(
sep = "<br/>"
, "<strong>Encounter: </strong>"
, PtNo_Num
, "<strong>Service Line: </strong>"
, LIHN_Line
, "<strong>Hospitalist/Private: </strong>"
, Hospitalist_Private
, "<strong>Payor Category </strong>"
, Payor_Category
, "<strong>SOI: </strong>"
, SOI
, "<strong>Readmit: </strong>"
, Readmit_Count
, "<strong>Address: </strong>"
, FullAddress
)
)
, group = df
, clusterOptions = markerClusterOptions(
removeOutsideVisibleBounds = F
, labelOptions = labelOptions(
noHide = F
, direction = 'auto'
)
)
)
}
)
# Add baseGroups and overlayGroups to map
ClusterMapLIHN <- ClusterMapLIHN %>%
addLayersControl(
baseGroups = c("OSM (default)", "CartoDB.Positron")
, overlayGroups = names(LIHNCluster.df)
, options = layersControlOptions(
collapsed = TRUE
)
)
# Add and awesome marker
ClusterMapLIHN <- ClusterMapLIHN %>%
addAwesomeMarkers(
lng = sv_lng
, lat = sv_lat
, icon = hospMarker
, label = "BMHMC"
, popup = HospPopup
)
ClusterMapLIHN