Skip to content
  • Nice! I see this when the app loads "Error: a character vector argument expected". but doesn't affect it working at all

  • Yeah, I think that happens on startup because the plot gets called before you've even had a chance to load a shapefile. There should be some test conditions checked first - its why you see a lot of req(foo$bar) in shiny code...

  • Hi, I have this error when i try to upload a shapefile : "Error in xy.coords: 'x' and 'y' lenghts differ"

    Do you know any solution ? thanks a lot !

  • Can you read the shapefile correctly using st_read? Are you uploading all four shapefile components (ie the .shp, .shx, .dbf and .prj files)? I just tested this snippet and it still works for me.

    Edited by Barry Rowlingson
  • I can read the shapefile :

    *Listening on http://127.0.0.1:7786
    Upload dir is/tmp/RtmptMVO68/984dcb00eb9da2996c5a8eac
    Reading layer `mmr_polbnda_adm0_250k_mimu' from data source `/tmp/RtmptMVO68/984dcb00eb9da2996c5a8eac/mmr_polbnda_adm0_250k_mimu.shp' using driver `ESRI Shapefile'
    Simple feature collection with 1 feature and 6 fields
    geometry type:  MULTIPOLYGON
    dimension:      XY
    bbox:           xmin: 92.17275 ymin: 9.671252 xmax: 101.1699 ymax: 28.54554
    epsg (SRID):    4326
    proj4string:    +proj=longlat +datum=WGS84 +no_defs
    Warning: Error in xy.coords: 'x' and 'y' lengths differ*

    I'm uploading just the four shapefile components yes. What I changed from your code is the position of the "plot(st_geometry(inShp()))".

    It's now here :

    leaflet() %>%
          addProviderTiles("Esri.WorldImagery", group = "Esri World Imagery", options = providerTileOptions(minZoom = 2, maxZoom = 17)) %>%
          addTiles(group = "OSM", options = providerTileOptions(minZoom = 2, maxZoom = 17)) %>%
          setView(lng = 96.221,lat = 20.792, zoom = 6 ) %>%
         ** plot(st_geometry(inShp()))**
          addLayersControl(baseGroups = c("Esri World Imagery", "OSM"))
      })

    Is that the problem ?

    Edited by Victor Réchou
  • Yes, that's not how the leaflet function works. You need to add a layer to it with one of the addSomething functions. Get it working outside of shiny before adding that complexity. Test it at the command line. Much faster turnaround.

  • Do you think that is possible ? To browse a shapefile on a Shiny app, and display it on Leaflet ? Because, i have some trouble finding good examples.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment