My shiny app relies on custom packages hosted on github, along with sf
and nngeo
amongst others. One of these custom packages is an API wrapper to an API that requires authentication. One of the processes in the app is to calculate sf::st_join()
on two sf
objects with the same CRS.
All this works fine on my system, rendering a Shiny dashboard with maps that project all objects correctly. When I publish to ShinyIO, however, I receive the following error. It seems that ShinyIO thinks the two objects have different coordinate reference systems; but I have verified that this is not the case. Please can you help?
Attaching package: ‘shinydashboard’
The following object is masked from ‘package:graphics’:
box
Loading required package: sf
Linking to GEOS 3.5.1, GDAL 2.2.2, PROJ 4.9.2
Loading required package: nngeo
Loading required package: dplyr
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
Loading required package: tidyr
Loading required package: lubridate
Attaching package: ‘lubridate’
The following objects are masked from ‘package:base’:
date, intersect, setdiff, union
Loading required package: stringr
Loading required package: magrittr
Attaching package: ‘magrittr’
The following object is masked from ‘package:tidyr’:
extract
Error in value[[3L]](cond) : 'x' and 'y' need to be in the same CRS
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
I believe I've isolated the problem to this function, but again it works fine on my system and I've checked all the inputs so I'm not sure why it would fail on ShinyIO.
gtcharge <- function(geotab){
geotab <- geotab %>%
dplyr::filter(dplyr::across(dplyr::contains("stopPoint"), ~!is.na(.x))) %>%
sf::st_as_sf(coords = c("stopPoint.x", "stopPoint.y"), crs = 4326) %>%
sf::st_transform(27700)
distance_to_nearest <- nngeo::st_nn(geotab, ncr, sparse = TRUE, k = 1, maxdist = Inf,
returnDist = TRUE, progress = TRUE)
sf::st_join(geotab, ncr, join = sf::st_nearest_feature, left = TRUE) %>%
dplyr::bind_cols(list(dist = unlist(distance_to_nearest$dist)))
}