Rstudio Connect: Can't get sf to work correctly for RStudio Connect

Ubuntu 16.04 LTS
Current version of RStudio Connect

This has been the bane of my existence for RStudio Connect. Boss wants a minimum distance to a shape file calculation and the best I've found is the "sf" package. But man is it complicated to get up and running. The st_nearest_feature() function requires GEOS 3.6.1 which isn't on a repository, so needs to be built by source.

I removed all GEOS/GDAL/PROJ4 libraries and built each by source. I built GDAL to ensure it connects statically to GDAL.

I have GEOS 3.7.2
PROJ4: 4.9
GDAL: 2.3.0

But now when I publish my app, I get:

08/07 13:23:29.077

Loading required package: sf

08/07 13:23:29.310

Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):

08/07 13:23:29.310

unable to load shared object '/opt/rstudio-connect/mnt/packrat/3.6.1/v2/library/sf/976335ee4fab91caf68dd574531dba8a/sf/libs/':

08/07 13:23:29.310 cannot open shared object file: No such file or directory

I don't have the file anywhere in Ubuntu. I have:


I tried getting rid of GDAL built by source and installing the library libgdal-dev, but it pulls in the libgeos files too.

I'm able to install sf with no errors in Ubuntu and am able to run the app just fine locally, but I still get the above error. I've googled for hours and checked up and down the sf github. I'm fairly confident I don't have multiple GDAL/GEOS/PROJ installed. Do I need to link some paths or something?

Have you tried to install the development packages for GDAL, GEOS and PROJ from the Ubuntu GIS PPA at