我无法在闪亮的应用中添加不同的图层。我想添加一组多边形以及一组圆形标记以及一组任意(.png)图标。我有一组geojson文件,这些文件被添加到for循环中,该循环包含在带有函数的observe({})语句中 map $ addGeoJSON(x)其中x是带坐标的要素。 'map'对象由命令
创建public class Decorator {
abstract class I implements DefaultView { I render(); }
static class A implements I { public I render() { System.out.print( 'A' ); } }
static abstract class D implements I {
private I core;
public D( I inner ) { core = inner; }
public I render() { return core.render(); }
}
static class X extends D {
public X( I inner ) { super( inner ); }
public I render() {
I i = super.render();
i.setBackgroundColor();
}
}
static class Y extends D {
public Y( I inner ) { super( inner ); }
public I render() {
I i = super.render();
View v = new View();
//This is objective-c similar syntax,
//I don't know what's equivalent to Java
i.addSubview(v);
}
}
public static void main( String[] args ) {
I i1 =new X( new A() )
I i2= new Y( new X( new A() ) )};
I whatINeed1 = i1.render();
I whatINeed2 = i2.render;
}
这一切都很好,花花公子,多边形得到了很好的补充。我也想承诺添加多边形的这种方式。这不应该改变。
当我尝试以相同的方式将标记添加到该地图对象时发生错误(例如,使用map $ addMarkers(....))以下是错误以及尝试在其中添加标记的应用程序的代码期望的方式和失败。 下面带有地震数据的闪亮应用程序重新创建了我的错误
map <- createLeafletMap(session, 'map')
(How)我可以在坚持使用createLeafletMap()函数时正确添加标记吗?
"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)
答案 0 :(得分:0)
尝试:
library(dplyr)
df <- filteredData()
leafletProxy("map") %>%
addMarkers(df, lng = ~Lon, lat = ~Lat, popup = paste(as.character(df$mag) )
<{1>} 下的