在我的Shiny App中,我的小叶整块图仅在最近的软件包更新到小叶2.0.1之后显示了第一个多边形。
我改编了Leaflet for R网页中的代码,该代码过去一直有效。
这是MRE:
library(sf)
library(leaflet)
From http://leafletjs.com/examples/choropleth/us-states.js
states <- read_sf("~/Downloads/cb_2017_us_state_20m/cb_2017_us_state_20m.shp")
leaflet(states) %>%
setView(-96, 37.8, 2) %>%
addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.5,
fillColor = ~colorQuantile("YlOrRd", ALAND)(ALAND),
highlightOptions =
highlightOptions(color = "white",
weight = 2, bringToFront = TRUE, dashArray = ""))
仅显示第一个多边形的输出:
我已经检查了数据集和shapefile,它看起来正确,可以使用plot
函数成功绘制。
答案 0 :(得分:1)
这是leaflet
v 2.x.x
如果您删除了dashArray = ""
命令,它应该可以正常显示,即
states <- read_sf("~/Downloads/cb_2017_us_state_20m/cb_2017_us_state_20m.shp")
leaflet(states) %>%
setView(-96, 37.8, 2) %>%
addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.5,
fillColor = ~colorQuantile("YlOrRd", ALAND)(ALAND),
highlightOptions =
highlightOptions(color = "white",
weight = 2, bringToFront = TRUE))
答案 1 :(得分:1)
我找到了解决方案,那就是分配dashArray = NULL
。在Leaflet for R网页中,代码包含dashArray = ""
。为dashArray
分配一个空字符串,该字符串曾经作为默认值使用,但是现在它使传单仅绘制第一个多边形。
library(sf)
library(leaflet)
From http://leafletjs.com/examples/choropleth/us-states.js
states <- read_sf("~/Downloads/cb_2017_us_state_20m/cb_2017_us_state_20m.shp")
leaflet(states) %>%
setView(-96, 37.8, 2) %>%
addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.5,
fillColor = ~colorQuantile("YlOrRd", ALAND)(ALAND),
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE,
dashArray = NULL
))
这将输出正确的图: