并非所有在带有addPolylines的Leaflet中显示的SpatialLines

时间:2018-11-15 08:50:42

标签: r shiny leaflet

我正在使用R-Shiny开发网络应用。

我的问题是SpatialLinesDataFrame映射中并未显示Leaflet(SLDF)中的所有行。欢迎大家提出意见。数据集已存储here

我的代码:

#convert raster layer (ras) to SLDF
rtc <- rasterToContour(ras)

leaflet() %>%
addPolylines(data=rtc, group="contour", layerId="contour_pr",noClip = TRUE)

结果:

Leaflet中仅显示内部轮廓线

enter image description here

或者,所有行都使用R绘图函数(plot(rtc))显示 enter image description here

版本信息:

R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.1 LTS
other attached packages:
[1] igraph_1.2.2 rgeos_0.3-25 bindrcpp_0.2.2 ggplot2_3.1.0 withr_2.1.2
[6] labeling_0.3 V8_1.5 RColorBrewer_1.1-2 stringr_1.3.1 ncdf4_1.16
[11] yaml_2.2.0 data.table_1.11.4 mapview_2.5.0 sf_0.6-3 DT_0.4
[16] geometa_0.3-0 rgdal_1.3-6 raster_2.6-7 sp_1.3-1 dplyr_0.7.6
[21] plyr_1.8.4 leaflet.extras_1.0.0 leaflet_2.0.2 shinyBS_0.61 
shinyjs_1.0
[26] shinydashboard_0.7.0 shiny_1.1.0

1 个答案:

答案 0 :(得分:1)

有两种方法可以解决此问题。

  1. 如果要一次全部添加,请添加 update作为SpatialLinesDataFrame函数中的数据集(示例1 )。
  2. 比较丑陋,但也可以单独添加它们(示例2 )。

示例1

leaflet

示例2

leaflet(data=rtc) %>% addTiles() %>% addPolylines()

结果

enter image description here