我有多个光栅 .tif 文件,我想在 pickerInput、socal_norbaja_coast_gdes、southern_mountains_gdes 和 sonoran_basin_gdes 中显示。我还想包括 11 个其他生态区,但目前正在处理 3 个。在我 UI 的 sideBarPanel 中,我有这段代码:
shinyWidgets::pickerInput(inputId = "ecoregion_type_input",
label = "Select ecoregion:",
choices = c("socal_norbaja_coast_gdes", "southern_mountains_gdes", "sonoran_basin_gdes"),
options = pickerOptions(actionsBox = TRUE),
selected = c("socal_norbaja_coast_gdes"),
multiple = TRUE),), # End SideBarPanel
mainPanel(
# TMAP UI
tmapOutput("map")))),
我的服务器看起来像这样:
server <- function(input, output, session) {
tm_df <- reactive({
# proxy <- tmapProxy("map", session)
validate(
need(length(input$ecoregion_type_input) > 0, "Select more than one ecosystem"))
# tm <- tm_raster() # shape(socal_norbaja_coast_gdes)
if ("socal_norbaja_coast_gdes" %in% input$ecoregion_type_input) {
tm_shape(socal_norbaja_coast_gdes) + tm_raster()
} else if ("southern_mountains_gdes" %in% input$ecoregion_type_input) {
tm_shape(southern_mountains_gdes) + tm_raster()
} else if ("sonoran_basin_gdes" %in% input$ecoregion_type_input) {
tm_shape(sonoran_basin_gdes) + tm_raster()
}
# not sure if below is relevant
tm_df <- tm %>%
filter(ecoregion_type %in% c(input$ecoregion_type_input))
tm_df
})
output$map <- renderTmap({
tm
})
}
生态区没有显示,我什至无法点击下拉窗口来显示生态区。但是,我能够在交互式地图中看到图层按钮,并且能够选择和取消选择第一个生态区。如何使带有 pickerInput 的下拉窗口可点击并能够显示生态区?有没有不使用 if 语句的更简单的方法来做到这一点?感谢您的帮助!