【发布时间】:2017-07-29 17:51:26
【问题描述】:
我无法在闪亮的应用程序中添加不同的图层。我想添加一组多边形以及一组圆形标记以及一组任意(.png)图标。我有一组 geojson 文件,它们被添加到一个 for 循环中,该循环包含在带有函数的 observe({}) 语句中 map$addGeoJSON(x) 其中 x 是具有坐标的特征。 'map' 对象由命令创建
map <- createLeafletMap(session, 'map')
这一切都很好,而且多边形也很好。我也想采用这种添加多边形的方式。这不应该改变。
当我尝试以相同的方式(例如,使用 map$addMarkers(....) )向该地图对象添加标记时会发生错误 下面是错误和尝试在所需的方式并失败。 下面带有地震数据的闪亮应用重现了我的错误
"Listening on ...
Warning: Error in observerFunc: attempt to apply non-function
Stack trace (innermost first):
56: observerFunc [C:/Users/jbz/Desktop/leaflet-map-question.R#35]
1: runApp
ERROR: [on_request_read] connection reset by peer"
library(shiny)
library(leaflet)
library(RColorBrewer)
ui <- bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
leafletMap("map", width = "100%", height = "100%",
options=list(center = c(40.736, -73.99), zoom = 14)),
absolutePanel(top = 10, right = 10,
sliderInput("range", "Magnitudes", min(quakes$mag), max(quakes$mag),
value = range(quakes$mag), step = 0.1
),
selectInput("colors", "Color Scheme",
rownames(subset(brewer.pal.info, category %in% c("seq", "div")))
),
checkboxInput("legend", "Show legend", TRUE)
)
)
server <- function(input, output, session) {
filteredData <- reactive({
quakes[quakes$mag >= input$range[1] & quakes$mag <= input$range[2],]
})
colorpal <- reactive({
colorNumeric(input$colors, quakes$mag)
})
map <- createLeafletMap(session, 'map')
observe({
df <- filteredData()
map$addMarkers(
lng=df$Lon, lat=df$Lat, popup = paste(as.character(df$mag)))
})
}
shinyApp(ui, server)
(如何)在坚持使用函数createLeafletMap()的同时正确添加标记?
map <- createLeafletMap(session, 'map')
【问题讨论】:
-
你也可以提供你的
createLeafletMap()函数吗? -
createLeafletMap已弃用 -
案例错误:
lng=df$lon, lat=df$lat -
试图复制rpubs.com/Sylvie/cityBikeApp上的结构