Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R keeps on saying argument is empty when the argument has data

    # 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)

In the code above I am trying to select the region then select the data points for that particular region and show it as a GIS dashboard on shiny.
So I filtered the data points by the regions in the code.
Any time I try to run it, it shows the error

Error in list(Airports =
gis_data_TOGO_Airport[gis_data_TOGO_Airport$state == : argument 9
is empty

And I comment the line then it just goes to the next argument with the same error till they are no arguments left to be called.
But all the data are available.
Please I will love if you could help me with a solution so I can create a nice GIS of the country

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are getting that message because of the last line in your definition of "Savanes Region":

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

You have an extra comma after the expression for Waterways.
You have the same problem at the end of "Kara Region".

Remove the commas at the end of those lines, and the error should go away.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading