我已经设置了一个简单的传单地图,闪亮的server.R
看起来像这样:
(请从Dropbox获取RDS数据以获得可重现的示例)
Server.R
test_polygons <- readRDS('test_polygons.RDS') # Sind die Polygon-Shapefiles transformiert auf WGS84 für Bezirke
#some merging....
#we use sample data instead
test_polygons@data$sample <- runif(nrow(test_polygons@data))
#Create some nice popups
world_popup <- function(modell){
niveau <- test_polygons@data[, modell]
probs <- seq(0, 1, length.out = 5 + 1)
niveau <- cut(niveau, breaks=quantile(niveau, probs, na.rm = TRUE, names = FALSE), labels=paste('level', 0:4), include.lowest = TRUE)
niveau <- as.character(niveau)
niveau <- factor(niveau, labels=)
paste0("<strong>Bezirk: </strong>",
as.character(test_polygons@data$ID),
"<br><strong><br>",
"</strong>",
"<strong>Level: </strong>",
niveau
)
}
tiles <- "http://{s}.tile.stamen.com/toner-lite/{z}/{x}/{y}.png"
attribution <- 'Map tiles by <a target="_blank" href="http://stamen.com">Stamen Design</a>, under <a target="_blank" href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Map data by <a target="_blank" href="http://www.naturalearthdata.com/">Natural Earth</a>.'
# produce the leaflet map ====
pal <- colorQuantile("YlOrRd", NULL, n = 5)
m.sample <- leaflet(data = test_polygons) %>%
addTiles(urlTemplate = tiles,
attribution = attribution) %>%
setView(13.782778, 47.61, zoom = 7) %>%
addPolygons(fillColor = ~pal(test_polygons$sample),
fillOpacity = 0.8,
color = "#000000",
weight = 1,
popup = world_popup('sample'))
# start the server part
server <- function(input, output, session) {
output$query <- renderText({
as.character(parseQueryString(session$clientData$url_search))
})
output$mymap <- renderLeaflet({
m.sample
})
}
ui.R
虽然UI非常简单:
require(leaflet)
require(shiny)
ui <- fluidPage(
column(width=12,
leafletOutput("mymap", height="200px")#, height="700px")
)
)
这在我的台式电脑上运行正常。但是,一旦我尝试在我的服务器上访问它,传单地图加载速度非常慢。特别是如果我将高度改为100%,它会完全停止加载。所以这是我的问题:
非常感谢你的帮助!
答案 0 :(得分:2)
从简化SP-Object的注释开始就可以了。我在QGis中导入了底层shapefile并通过
进行了调整 Vector => Geometry Tools => Simplify geometries
现在工作得更快。更多信息可以通过以下方式找到:
Qgis-Stackexchange或Documentation。
感谢您的帮助!