r - 传单 + 闪亮:addLegend 值中的“参数长度为零”
问题描述
我正在开发一个闪亮的应用程序来显示等值线图,使用传单和 shapefile 来添加多边形。外面闪亮的一切都很好,但是闪亮的我在使用时遇到了问题addLegend
,如下所示:
mypal <- reactive({
colorBin(palette = "RdYlBu", domain = get("map_fires")[[paste0("qm_", selectedYear())]],
bins = 5, reverse = TRUE, pretty = FALSE,
na.color = "#FFFAFA")
})
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles("OpenStreetMap.Mapnik") %>%
addPolygons(data = map_fires,
stroke = TRUE, weight = 1, smoothFactor = 0.2, fillOpacity = 0.3,
fillColor = ~mypal()(get("map_fires")[[paste0("qm_", selectedYear())]]),
highlight = highlightOptions(
weight = 5,
color = "#666",
fillOpacity = 0.7,
bringToFront = TRUE),
label= lapply(stats_labels(), HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(position = "bottomright", pal = ~mypal(),
values = ~get("map_fires")[[paste0("qm_", selectedYear())]],
opacity = 1)
})
上面的代码返回:
Warning: Error in if: argument is of length zero
104: addLegend
...
我paste0("qm_", selectedYear())
用来指代具有年度数据的不同列。
我相信问题出在values = ~get("map_fires")[[paste0("qm_", selectedYear())]]
,但不知道为什么。我已经尝试在 上指定数据集addLegend
,并在上放置特定列values =
(即,不依赖于 的反应值selectedYear()
),但无济于事。
外面闪亮的东西与下面的代码配合得很好(我一直在使用get("map_fires")[[paste0("qm_", 2018)]]
,改变selectedYear()
了特定的年份,只是为了更好地展示我的情况):
mypal <- colorBin(palette = "RdYlBu", domain = get("map_fires")[[paste0("qm_", 2018)]],
bins = 5, reverse = TRUE, pretty = FALSE,
na.color = "#FFFAFA")
leaflet() %>%
addProviderTiles("OpenStreetMap.Mapnik") %>%
addPolygons(data = map_fires,
stroke = TRUE, weight = 1, smoothFactor = 0.2, fillOpacity = 0.3,
fillColor = ~mypal(get("map_fires")[[paste0("qm_", 2018)]]),
highlight = highlightOptions(
weight = 5,
color = "#666",
fillOpacity = 0.7,
bringToFront = TRUE),
label= lapply(stats_labels, HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(position = "bottomright", pal = mypal,
values = get("map_fires")[[paste0("qm_", 2018)]],
opacity = 1)
我错过了什么吗?
解决方案
推荐阅读
- python - 使用 google/protobuf/empty.proto 在没有参数的情况下调用 python grpc 方法期间的 TypeError
- react-native - 在 ios 上的 react-native-share 中,我们需要知道为什么共享选项弹出屏幕会立即被关闭?
- c - 内联和标题守卫之间的区别
- javascript - 如何将文件或文件夹移动到 google drive api 中的另一个文件夹?
- c++ - 如何在不同的 QThreads 中运行函数
- reactjs - 当另一个字段被更改时,Ant 设计表单会更新一个字段
- c++ - C++ 指针的引用可以为空吗?
- list - Haskell - 附加到列表列表中的列表并返回更新的列表列表
- numpy - 我正在使用掩码对 numpy 数组进行切片,但输出被展平。如何保留列数?
- email - TYPO3 direct_mail_subscription Double-Opt-In-Out 未激活