I have an API that calculated the distance to coast given lat/lon coordinates. I use the shape file found from NOAA Shoreline.
Everything works fine if I run the API locally, but when I publish it to RStudio Connect, I get an internal server 500 error. I also published the default plumber demo and it works just fine, so I'm not sure if it has something to do with the sf package or with the shape file.
The server is set up on Ubuntu 16.04 and I'm using R version 3.4.3. I also believe I have all of the proper Ubuntu installed. I'm not familiar enough with Ubuntu to know where to start debugging. Below is the code I'm using.
library(plumber)
library(sf)
library(tidyverse)
#* Return the distance to coast
#* @param lon is the longitude
#* @param lat is the latitude
#* @post /distance
function(lon,lat){
coords <- data.frame(Longitude = as.numeric(lon), Latitude = as.numeric(lat)) %>%
st_as_sf(coords = c('Longitude','Latitude'))
shape <- read_sf("us_medium_shoreline.shp")
dist <- st_nearest_feature(coords,shape)/1609
}
oddly enough, if I create a different way of calculating it, it works just fine:
Actually, I think it may be just the st_nearest_feature. I'm using Ubuntu R 3.4.3 and I think st_nearest_feature requires 3.6.1. Can anyone verify this assumption is correct before I update R?
Edit: I updated to 3.6.1 in both Ubuntu 16.04 and my local system and still the API is not working. I do think it's because of the st_nearest_feature function. I also updated the verion of GEOS and it's now geos-3.7.2, but that didn't fix it either.
I get the error "<Rcpp::exception in CPL_geos_nearest_feature(st_geometry(x), st_geometry(y)): GEOS version 3.6.1 required for selecting nearest features>"