diff --git a/DESCRIPTION b/DESCRIPTION index 617345b..17ba7e6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: LifemapR Title: Data Visualisation on 'Lifemap' Tree Version: 1.1.0 -Imports: leaflet, shiny, jsonlite, dplyr, leaflet.minicharts, htmltools, rlang +Imports: leaflet, shiny, jsonlite, dplyr, leaflet.minicharts, htmltools, rlang, RCurl Authors@R: c( person("Cassandra", "Bompard", role = "aut", email = "cassbomp68@gmail.com"), person("Damien M.", "de Vienne", role = "aut", email = "damien.de-vienne@univ-lyon1.fr"), diff --git a/NAMESPACE b/NAMESPACE index bd3d434..11a23e3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(lm_piecharts) export(make_newick) export(pass_infos) export(pass_infos_discret) +importFrom(RCurl,url.exists) importFrom(dplyr,bind_rows) importFrom(dplyr,distinct) importFrom(dplyr,full_join) @@ -46,7 +47,7 @@ importFrom(leaflet,providerTileOptions) importFrom(leaflet,renderLeaflet) importFrom(leaflet.minicharts,addMinicharts) importFrom(leaflet.minicharts,clearMinicharts) -importFrom(rlang,.data) +importFrom(rlang,data) importFrom(shiny,fluidPage) importFrom(shiny,isolate) importFrom(shiny,observe) diff --git a/R/build_Lifemap.R b/R/build_Lifemap.R index 5f0e3ea..1da91a8 100644 --- a/R/build_Lifemap.R +++ b/R/build_Lifemap.R @@ -22,7 +22,8 @@ #' #' @importFrom jsonlite fromJSON #' @importFrom dplyr bind_rows distinct -#' @importFrom rlang .data +#' @importFrom rlang data +#' @importFrom RCurl url.exists #' #' @export #' @examples @@ -52,6 +53,10 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base","fr","virus"), verbose= # download full data for chosen basemap if (verbose) cat("Downloading basemap coordinates...\n") + + + # ADD A CONTROL HERE TO TEST IF THE URL IS VALID. + if (!url.exists(basemap_url)) stop ("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.") load(url(basemap_url), envir=lifemap_basemap_envir) # add LUCA LUCA <- data.frame(taxid=0,lon=0, lat=-4.226497,sci_name="Luca",zoom=5) diff --git a/R/display_map.R b/R/display_map.R index eb2b9dd..756682c 100644 --- a/R/display_map.R +++ b/R/display_map.R @@ -13,6 +13,7 @@ #' @return An HTML widget object with graphics layers. #' @export #' @importFrom leaflet leaflet addTiles providerTileOptions +#' @importFrom RCurl url.exists #' #' @examples #' display_map() @@ -27,6 +28,7 @@ display_map <- function(df = NULL,basemap = c("fr","ncbi", "base","virus")) { } else if (basemap == "virus"){ display="http://virusmap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" } + if (!url.exists(display)) stop ("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.") m <- leaflet::leaflet(df) |> leaflet::addTiles(display, options = leaflet::providerTileOptions(minZoom = 5, maxZoom = 50)) return(m)