我开始在 R's Shiny 中使用传单,我正在使用 RStudio。我想创建一个带有起点和终点标记的地图,这些标记可以通过用户输入进行更改。因为我有很多标记要管理,所以我想使用集群插件所以我创建了一个闪亮的服务器:
server <- function(input, output, session) {
reactiveData <- reactiveValues(
origs = df.origins.total,
dests = df.destinations.total
)
mydata <- reactive({
mydf = data.frame(orig_lat=df.origins.total$lat,
orig_lon=df.origins.total$lon,
dest_lat=df.destinations.total$lat,
dest_lon=df.destinations.total$lon)
print(str(mydf))
return(mydf)
})
observe({
leafletProxy("map",data=mydata()) %>%
clearGroup("Destinations") %>%
addMarkers(
lng=~dest_lon,
lat=~dest_lat,
icon = uix.destMarker,
group = "Destinations",
clusterOptions = markerClusterOptions(
))
})
observe({
leafletProxy("map",data=mydata()) %>%
clearGroup("Origins") %>%
addMarkers(
lng=~orig_lon,
lat=~orig_lat,
icon = uix.origMarker,
group = "Origins",
clusterOptions = markerClusterOptions(
))
})
observe({
leafletProxy("map",data=mydata()) %>%
addLayersControl(overlayGroups = c("Origins","Destinations"))
})
output$map <- renderLeaflet({
leaflet() %>%
addTiles()%>%
})
}
奇怪的是,这段代码有时有效,有时无效,这意味着:它要么向我显示起点和终点,要么只显示终点。当只显示目的地时,我正在使用 Firefox 的检查器,它告诉我:
TypeError: _leaflet2.default.markerClusterGroup is undefined
leaflet.js:1273:7
这导致了这条线
clusterGroup = _leaflet2.default.markerClusterGroup.layerSupport(clusterOptions);
我想我已经正确安装了这些软件包,因为它们有时可以工作。即使发生错误,聚类仍然适用于显示的标记。我的数据集每个都有大约 2400 个标记。将所有观察者调用合并到一个观察者中也不会改变行为。我的数据集很大吗?我必须使用不同的顺序吗?我真的没有任何想法,任何帮助将不胜感激!