Skip to content

Commit

Permalink
Update url checking in 'build_lifemap()' and 'display_map()', using t…
Browse files Browse the repository at this point in the history
…ryCatch
  • Loading branch information
aursiber committed Jul 30, 2024
1 parent 9727f34 commit 07c9462
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
23 changes: 17 additions & 6 deletions R/build_Lifemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,22 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos
stop(sprintf('%s is not a working basemap, try c("base", "fr", "ncbi" or "virus")', basemap))
}

# download full data for chosen basemap
if(verbose) cat("Downloading basemap coordinates...\n")

# control to test if the url is valid
if(!url.exists(basemap_url)) {
y <- tryCatch({
load(url(basemap_url), envir = lifemap_basemap_envir)
},
warning = function(w) {
message("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")
} else {
return(NA)
},
error = function(e) {
message("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")
return(NA)
}
)

if(!is.na(y)) {
# download full data for chosen basemap
if(verbose) cat("Downloading basemap coordinates...\n")
load(url(basemap_url), envir = lifemap_basemap_envir)

# add LUCA
Expand Down Expand Up @@ -111,5 +120,7 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos
class(lm_obj) <- c("lifemap_obj", "list")

return(lm_obj)
} else {
return(NA)
}
}
21 changes: 17 additions & 4 deletions R/display_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,24 @@ display_map <- function(df = NULL, basemap = c("fr","ncbi", "base","virus")) {
display="https://virusmap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
}
url2check<-strsplit(display, "osm_tiles")[[1]][1]
if (!url.exists(url2check)) {
message("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")
} else {
m <- leaflet::leaflet(df) |>

m <- tryCatch({
leaflet::leaflet(df) |>
leaflet::addTiles(display, options = leaflet::providerTileOptions(minZoom = 5, maxZoom = 50))
},
warning = function(w) {
message("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")
return(NA)
},
error = function(e) {
message("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")
return(NA)
}
)

if(!all(is.na(m))) {
return(m)
} else {
return(NA)
}
}

0 comments on commit 07c9462

Please sign in to comment.