在Shiny selectInput下拉列表中将S4类强制为向量

时间:2019-07-05 21:29:24

标签: r shiny geojson s4

我正在尝试根据侧边栏中的区域选择(10个选项),让我的Shiny应用程序显示GeoJSON文件的子集(加利福尼亚州的区域)(带有公共水系统边界区域数据)。下拉菜单。

# global.R
library(shiny)
library(leaflet)
library(dplyr)
library(rgdal)

# bring in data from public water service areas

#service_areas <- readOGR("https://trackingcalifornia.org/geoserver/ows?service=wfs&version=1.1.0&request=GetFeature&typeName=water:service_areas&srsName=epsg:4326&outputFormat=json")

# break counties in regions (based on 2020 census)
superior_ca_counties <- c("BUTTE", "COLUSA", "EL DORADO", "GLENN", "LASSEN", "MODOC", "NEVADA", "PLACER","PLUMAS", "SACRAMENTO","SHASTA", "SIERRA", "SISKIYOU","SUTTER", "TEHAMA", "YOLO", "YUBA")
north_coast_counties <- c("DEL NORTE", "HUMBOLDT", "LAKE", "MENDOCINO", "NAPA", "SONOMA", "TRINITY")
sf_bay_area_counties <- c("ALAMEDA", "CONTRA COSTA", "MARIN", "SAN FRANCISCO", "SAN MATEO", "SANTA CLARA", "SOLANO")
nor_sj_valley_counties <- c("ALPINE", "AMADOR", "CALAVERAS", "MADERA", "MARIPOSA", "MERCED", "MONO", "SAN JOAQUIN", "STANISLAUS", "TUOLUMNE")
central_coast_counties <- c("MONTEREY", "SAN BENITO", "SAN LUIS OBISPO", "SANTA BARBARA", "SANTA CRUZ", "VENTURA")
so_sj_valley_counties <- c("FRESNO", "INYO", "KERN", "KINGS", "TULARE")
inland_empire_counties <- c("RIVERSIDE", "SAN BERNARDINO")
los_angeles_county <- c("LOS ANGELES")
orange_county <- c("ORANGE")
imperial_sd_counties <- c("IMPERIAL", "SAN DIEGO")


regions <- list(superior_ca_counties, north_coast_counties, sf_bay_area_counties, nor_sj_valley_counties, central_coast_counties, so_sj_valley_counties, inland_empire_counties, los_angeles_county, orange_county, imperial_sd_counties)

fnsubset<-function(regions, areas){
  areas<-subset(service_areas, service_areas$d_prin_cnty_svd_nm==regions)
}

regional_areas <- lapply(regions, fnsubset)

#ui.R  


ui<-fluidPage(
  titlePanel("Source Water Locations"),
  mainPanel(
  leafletOutput('map', height=1000)),
  sidebarPanel(
  fluidRow(
  column(12,
  helpText("Select Region of interest"),
  selectInput("region", "Region:", c("Region 1: Superior CA"= regional_areas[[1]],
                                       "Region 2: North Coast"= regional_areas[[2]],
                                        "Region 3 : San Francisco Bay Area"= regional_areas[[3]],
                                        "Region 4 : Northern San Joaquin Valley"= regional_areas[[4]],
                                        "Region 5: Central Coast" = regional_areas[[5]],
                                        "Region 6: Southern San Joaquin Valley"= regional_areas[[6]],
                                        "Region 7: Inland Empire" = regional_areas[[7]],
                                        "Region 8: Los Angeles County"= regional_areas[[8]],
                                        "Region 9: Orange County"= regional_areas[[9]],
                                        "Region 10: San Diego-Imperial"= regional_areas[[10]]))
  )
  )
  )
)


# server.R

# leaflet map
map <- leaflet()%>% addTiles()


shinyServer(
  function(input, output){

    output$map <- renderLeaflet({
      map  <- addPolygons(data=input$region, popup = ~pwsid)
      map  
    })

  }
)

这是我收到的错误消息: 错误:没有用于将此S4类强制转换为向量的方法 是否有另一种访问区域S4类而不引起此错误的方法?

0 个答案:

没有答案