R 如何在闪亮的服务器上加速传单
我在shiny中设置了一个简单的传单地图,其中shinyR 如何在闪亮的服务器上加速传单,r,shiny,leaflet,R,Shiny,Leaflet,我在shiny中设置了一个简单的传单地图,其中shinyserver.R如下所示: (请从中获取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
server.R
如下所示:
(请从中获取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
})
}
test\u polygons从简化SP对象的注释开始。我在QGis中导入了基础shapefile,并通过
Vector => Geometry Tools => Simplify geometries
现在工作快多了。更多信息可通过以下途径找到:
或者
谢谢你的帮助 我认为多边形对于web应用程序来说是巨大的。首先尝试简化多边形,看看它是否有所改进。您可以查看基于传单构建的mapview,但使用大型数据集时速度更快(我认为他们使用js处理大型数据集),您可以使用rgeos
包中的gSimplify
在R中简化。
Vector => Geometry Tools => Simplify geometries