在R中为传单贴图添加多个图层
在我的闪亮应用程序中添加不同层时遇到问题。我想添加一组多边形、一组圆标记以及一组任意(.png)图标。我有一组geojson文件,它们被添加到一个for循环中,该循环用函数封装在一个observe({})语句中 映射$addGeoJSON(x),其中x是带有坐标的功能。“映射”对象由命令创建在R中为传单贴图添加多个图层,r,shiny,leaflet,polygon,R,Shiny,Leaflet,Polygon,在我的闪亮应用程序中添加不同层时遇到问题。我想添加一组多边形、一组圆标记以及一组任意(.png)图标。我有一组geojson文件,它们被添加到一个for循环中,该循环用函数封装在一个observe({})语句中 映射$addGeoJSON(x),其中x是带有坐标的功能。“映射”对象由命令创建 map <- createLeafletMap(session, 'map') map尝试: 库(dplyr) df% addMarkers(df,lng=~Lon,lat=~lat,popup=p
map <- createLeafletMap(session, 'map')
map尝试:
库(dplyr)
df%
addMarkers(df,lng=~Lon,lat=~lat,popup=paste(as.character,df$mag))
在observe
下,您也可以提供您的create传单映射()
函数吗?create传单映射
是不推荐的案例错误:lng=df$lon,lat=df$lat
尝试复制操作状态的结构:“(如何)在坚持使用函数create传单映射()的同时正确添加标记?”-您的答案是:否?映射仍然是使用create传单映射()
创建的renderLeaflet
会有所不同。警告:UseMethod中的错误:没有适用于“metaData”的方法应用于类为“NULL”的对象,并获得与HubertL相同的错误。UseMethod中的错误(“doResolveFormula”):没有适用于“doResolveFormula”的方法应用于类为“NULL”的对象。这里有相同的错误。我认为某个地方需要if(!is.NULL(x)){do something}
"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)
map <- createLeafletMap(session, 'map')
library(dplyr)
df <- filteredData()
leafletProxy("map") %>%
addMarkers(df, lng = ~Lon, lat = ~Lat, popup = paste(as.character(df$mag) )