当参数有数据时,R 一直说参数为空

问题描述 投票:0回答:1
    # TOGO
    # Reading each GeoJSON file and storing in a variable
    gis_data_TOGO_ADM1 <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/geoBoundaries-TGO-ADM1.geojson")
    gis_data_TOGO_ADM2 <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/geoBoundaries-TGO-ADM2.geojson")
    gis_data_TOGO_Airport <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_airport.geojson")
    # gis_data_TOGO_Buildings <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_buildings.geojson")
    gis_data_TOGO_Education_Facilities <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_education_facilities.geojson")
    gis_data_TOGO_Financial_Services <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_financial_services.geojson")
    gis_data_TOGO_Healthsites <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_healthsites.geojson")
    gis_data_TOGO_Health_Facilities <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_health_facilities.geojson")
    gis_data_TOGO_Populated_Places <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_populated_places.geojson")
    gis_data_TOGO_Railways <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_railways.geojson")
    gis_data_TOGO_Road <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_road.geojson")
    gis_data_TOGO_Sea_Ports <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_sea_ports.geojson")
    gis_data_TOGO_Waterways <- geojsonsf::geojson_sf("C:/Users/HP/OneDrive/Documents/Vitalera/data/gis/ecowas/togo/togo_waterways.geojson")
    
    
    
    
    
    
    # Define UI
    ui <- dashboardPage(
      dashboardHeader(title = "Interactive Map Dashboard"),
      dashboardSidebar(
        # Add a region selector dropdown
        selectInput("region", "Select Region", 
                    choices = c("Savanes Region", "Kara Region", "Plateaux Region", "Maritime Region", "Centrale Region"),
                    selected = "Savanes Region"),
        
        sidebarMenu(
          menuItem("Map", tabName = "map", icon = icon("map")),
          
          # Dynamically generated checkbox inputs based on selected region
          uiOutput("region_checkboxes")
        )
      ),
      dashboardBody(
        tabItems(
          tabItem(
            tabName = "map",
            fluidRow(
              box(
                title = "Interactive Map",
                status = "primary",
                solidHeader = TRUE,
                leafletOutput("map", height = "800px"), width = 12
              )
            )
          )
        )
      )
    )
    
    
    # Define Server Logic
    server <- function(input, output, session) {
      
      # Define data for each region
      region_data <- list(
        "Savanes Region" = list(
          # Airport = gis_data_TOGO_Airport[gis_data_TOGO_Airport$state == "Savanes Region", ],
          Education_Facilities = gis_data_TOGO_Education_Facilities[gis_data_TOGO_Education_Facilities$state == "Savanes Region", ],
          Healthsites = gis_data_TOGO_Healthsites[gis_data_TOGO_Healthsites$state == "Savanes Region", ],
          Financial_Services =gis_data_TOGO_Financial_Services[gis_data_TOGO_Financial_Services$state == "Savanes Region", ],
          Health_Facilities = gis_data_TOGO_Health_Facilities[gis_data_TOGO_Health_Facilities$state == "Savanes Region", ],
          Populated_Places = gis_data_TOGO_Populated_Places[gis_data_TOGO_Populated_Places$state == "Savanes Region", ],
          # Railways = gis_data_TOGO_Railways[gis_data_TOGO_Railways$state == "Savanes Region", ],
          Road = gis_data_TOGO_Road[gis_data_TOGO_Road$state == "Savanes Region", ],
          Sea_Ports = gis_data_TOGO_Sea_Ports[gis_data_TOGO_Sea_Ports$state == "Savanes Region", ],
          Waterways = gis_data_TOGO_Waterways[gis_data_TOGO_Waterways$state == "Savanes Region", ],
          
        ),
"Kara Region" = list(
      Airports = gis_data_TOGO_Airport[gis_data_TOGO_Airport$state == "Kara Region", ],
      Education_Facilities = gis_data_TOGO_Education_Facilities[gis_data_TOGO_Education_Facilities$state == "Kara Region", ],
      Healthsites = gis_data_TOGO_Healthsites[gis_data_TOGO_Healthsites$state == "Kara Region", ],
      Financial_Services = gis_data_TOGO_Financial_Services[gis_data_TOGO_Financial_Services$state == "Kara Region", ],
      Health_Facilities = gis_data_TOGO_Health_Facilities[gis_data_TOGO_Health_Facilities$state == "Kara Region", ],
      Populated_Places = gis_data_TOGO_Populated_Places[gis_data_TOGO_Populated_Places$state == "Kara Region", ],
      # Railways = gis_data_TOGO_Railways[gis_data_TOGO_Railways$state == "Kara Region", ],
      Road = gis_data_TOGO_Road[gis_data_TOGO_Road$state == "Kara Region", ],
      # Sea_Ports = gis_data_TOGO_Sea_Ports[gis_data_TOGO_Sea_Ports$state == "Kara Region", ],
      Waterways = gis_data_TOGO_Waterways[gis_data_TOGO_Waterways$state == "Kara Region", ],
    ),
      
      output$map <- renderLeaflet({
        leaflet(gis_data_TOGO_ADM1[gis_data_TOGO_ADM1$shapeGroup == "TGO", ]) %>%
          addProviderTiles(providers$CartoDB.Positron) %>%  # A clean base map
          addPolygons(
            fillColor = "antiquewhite",
            color = "gray80",
            weight = 1,
            data = gis_data_TOGO_ADM1[gis_data_TOGO_ADM1$shapeGroup == "TGO", ],
            label = ~shapeGroup,
            group = "Base Layer"
          )
      })
      
      
      
    }
    
    
    # Run the application
    shinyApp(ui = ui, server = server)

在上面的代码中,我尝试选择区域,然后选择该特定区域的数据点,并将其显示为闪亮的 GIS 仪表板。 因此,我按代码中的区域过滤了数据点。 每当我尝试运行它时,它都会显示错误

列表错误(机场 = gis_data_TOGO_Airport[gis_data_TOGO_Airport$state == :参数 9 是空的

我注释了该行,然后它就转到下一个参数,并出现相同的错误,直到它们不再有可供调用的参数。 但所有数据都是可用的。 如果您能帮助我找到解决方案,我会很高兴,这样我就可以创建一个漂亮的国家地理信息系统

r shiny arguments gis r-leaflet
1个回答
0
投票

您收到该消息是因为

region_data
定义中的最后一行:

      Waterways = gis_data_TOGO_Waterways[gis_data_TOGO_Waterways$state == "Kara Region", ],
    ),

Waterways
的表达式后面有一个额外的逗号。 删除该行末尾的逗号,错误就会消失。

© www.soinside.com 2019 - 2024. All rights reserved.