Skip to content

Commit

Permalink
added nice test of availability of urls
Browse files Browse the repository at this point in the history
  • Loading branch information
damiendevienne committed Mar 15, 2024
1 parent 5cfda02 commit 7e5f1ba
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Damien M.", "de Vienne", role = "aut", email = "[email protected]"),
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion R/build_Lifemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#'
#' @importFrom jsonlite fromJSON
#' @importFrom dplyr bind_rows distinct
#' @importFrom rlang .data
#' @importFrom rlang data
#' @importFrom RCurl url.exists
#'
#' @export
#' @examples
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions R/display_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 7e5f1ba

Please sign in to comment.