There are multiple options for storing spatial information. Some lend themselves for shiny import better than others.
The eponymous ESRI shapefile, spread over multiple files, is a known troublemaker - but it is comparatively easier to transfer a GeoJSON or a GeoPackage, both of which are contained in single file. The GeoJSON is a favorite of CS people (web developers and such), GeoPackage is popular with GIS folks (it works sort of like the original shp on steroids, with sqlite in place of dBase IV ).
I have also integrated in shiny upload of a {sf} package object stored as a RDS file and even an Excel file with lat-lon coordinates (points are easy).
By shapefile, I mean the ESRI shapefile that you highlight in your response. I have had trouble working with this, as you say, because multiple files are needed. Do you have any suggestions specifically for ESRI shapefile uploads for shiny users?
The most common, and most difficult format to work with. Makes sense, in a wicked way...
Are you in position to ask your users to upload a single zipped file? This could be unzipped someplace, e.g. in tempdir(), and read from there - would this work for your use case?
Also, sometimes sf::st_read() works more predictably than rgdal::readOGR(); testing is of course required.
I don't have a solution yet to upload more than one ESRI Shapefile, but maybe you can use a numericinput to understand how many ESRI files users/you need to upload and then use a renderUI to allow the users/you to upload many ESRI shapefile you need.
Thanks so much for your time. The code looks great and logical. I've had a go at using it in Rstudio, but it does not work unfortunately, I still get the "Warning: Error in ogrListLayers: Cannot open data source".
The app then crashes and highlights R#55, which is the:
map <- readOGR(paste(uploaddirectory, shpdf$name[grep(pattern="*.shp$", shpdf$name)], sep="/"))#, delete_null_obj=TRUE)
Excellent! Thanks so much for you help. I just got it to work.
I modified it slightly as I have some extra associated files i.e.
fileInput("filemap", "", accept=c('.shp','.dbf','.sbn','.sbx','.shx','.prj','.cpg'), multiple=TRUE)