From faed3e4363dcb113a30c7944c4a13c64283d3586 Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sat, 12 Jan 2019 10:39:10 +0100 Subject: [PATCH] leaflet.glify to leafgl --- DESCRIPTION | 2 +- NAMESPACE | 8 +-- R/glify-helpers.R | 6 +- R/glify-points.R | 72 +++++++++---------- R/glify-polygons.R | 61 ++++++++-------- R/glify-shiny.R | 22 +++--- README.md | 20 +++--- experiments/alabama_glify.R | 12 ++-- experiments/random_markers.R | 8 +-- .../Leaflet.glify/addGlifyPolygons.js | 2 +- .../Leaflet.glify/addGlifyPolygonsFl.js | 2 +- leaflet.glify.Rproj => leafgl.Rproj | 0 man/{addGlifyPoints.Rd => addGlPoints.Rd} | 24 +++---- man/{glifyOutput.Rd => leafglOutput.Rd} | 16 ++--- man/{renderGlify.Rd => renderLeafgl.Rd} | 18 ++--- tests/testthat.R | 4 +- tests/testthat/test-leafgl-addGlPoints.R | 20 ++++++ tests/testthat/test-leafgl-addGlPolygons.R | 14 ++++ ...test-glify-shiny.R => test-leafgl-shiny.R} | 6 +- 19 files changed, 175 insertions(+), 142 deletions(-) rename leaflet.glify.Rproj => leafgl.Rproj (100%) rename man/{addGlifyPoints.Rd => addGlPoints.Rd} (78%) rename man/{glifyOutput.Rd => leafglOutput.Rd} (82%) rename man/{renderGlify.Rd => renderLeafgl.Rd} (77%) create mode 100644 tests/testthat/test-leafgl-addGlPoints.R create mode 100644 tests/testthat/test-leafgl-addGlPolygons.R rename tests/testthat/{test-glify-shiny.R => test-leafgl-shiny.R} (67%) diff --git a/DESCRIPTION b/DESCRIPTION index 6c4a762..681c46e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,4 +1,4 @@ -Package: leaflet.glify +Package: leafgl Type: Package Title: Bindings for Leaflet.glify Version: 0.1.1 diff --git a/NAMESPACE b/NAMESPACE index 202d7b2..009e6d7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,9 +1,9 @@ # Generated by roxygen2: do not edit by hand -export(addGlifyPoints) -export(addGlifyPolygons) -export(glifyOutput) -export(renderGlify) +export(addGlPoints) +export(addGlPolygons) +export(leafglOutput) +export(renderLeafgl) importFrom(htmltools,tagList) importFrom(htmltools,tags) importFrom(leaflet,leafletOutput) diff --git a/R/glify-helpers.R b/R/glify-helpers.R index cd3365c..2161211 100644 --- a/R/glify-helpers.R +++ b/R/glify-helpers.R @@ -4,7 +4,7 @@ glifyDependencies = function() { htmltools::htmlDependency( "addGlifyPoints", '0.0.1', - system.file("htmlwidgets/Leaflet.glify", package = "leaflet.glify"), + system.file("htmlwidgets/Leaflet.glify", package = "leafgl"), script = c( "addGlifyPoints.js", "addGlifyPolygons.js", @@ -34,7 +34,7 @@ glifyDependenciesFl = function() { htmltools::htmlDependency( "addGlifyPoints", '0.0.1', - system.file("htmlwidgets/Leaflet.glify", package = "leaflet.glify"), + system.file("htmlwidgets/Leaflet.glify", package = "leafgl"), script = c( "addGlifyPoints.js", "addGlifyPolygonsFl.js", @@ -64,7 +64,7 @@ glifyDependenciesSrc = function() { htmltools::htmlDependency( "addGlifyPoints", '0.0.1', - system.file("htmlwidgets/Leaflet.glify", package = "leaflet.glify"), + system.file("htmlwidgets/Leaflet.glify", package = "leafgl"), script = c( "addGlifyPoints.js", "addGlifyPolygonsSrc.js", diff --git a/R/glify-points.R b/R/glify-points.R index 38dc8af..aeeb357 100644 --- a/R/glify-points.R +++ b/R/glify-points.R @@ -15,12 +15,12 @@ #' @param popup the name of the column in data to be used for popups. #' @param ... ignored. #' -#' @describeIn addGlifyPoints add points to a leaflet map using Leaflet.glify +#' @describeIn addGlPoints add points to a leaflet map using Leaflet.glify #' @examples #' \dontrun{ #' library(mapview) #' library(leaflet) -#' library(leaflet.glify) +#' library(leafgl) #' library(sf) #' library(colourvalues) #' library(jsonlite) @@ -39,7 +39,7 @@ #' system.time({ #' m = leaflet() %>% #' addProviderTiles(provider = providers$CartoDB.DarkMatter) %>% -#' addGlifyPoints(data = pts, color = cols, popup = "id") %>% +#' addGlPoints(data = pts, color = cols, popup = "id") %>% #' addMouseCoordinates() %>% #' setView(lng = 10.5, lat = 49.5, zoom = 9) #' }) @@ -47,15 +47,15 @@ #' m #' } #' -#' @export -addGlifyPoints = function(map, - data, - color = cbind(0, 0.2, 1), - opacity = 1, - weight = 10, - group = "glpoints", - popup = NULL, - ...) { +#' @export addGlPoints +addGlPoints = function(map, + data, + color = cbind(0, 0.2, 1), + opacity = 1, + weight = 10, + group = "glpoints", + popup = NULL, + ...) { if (is.null(group)) group = deparse(substitute(data)) if (inherits(data, "Spatial")) data <- sf::st_as_sf(data) @@ -96,14 +96,14 @@ addGlifyPoints = function(map, } ### via src -addGlifyPointsSrc = function(map, - data, - color = cbind(0, 0.2, 1), - opacity = 1, - weight = 10, - group = "glpoints", - popup = NULL, - ...) { +addGlPointsSrc = function(map, + data, + color = cbind(0, 0.2, 1), + opacity = 1, + weight = 10, + group = "glpoints", + popup = NULL, + ...) { if (is.null(group)) group = deparse(substitute(data)) if (inherits(data, "Spatial")) data <- sf::st_as_sf(data) @@ -171,14 +171,14 @@ addGlifyPointsSrc = function(map, ### via src -addGlifyPointsSrc2 = function(map, - data, - color = cbind(0, 0.2, 1), - opacity = 1, - weight = 10, - group = "glpoints", - popup = NULL, - ...) { +addGlPointsSrc2 = function(map, + data, + color = cbind(0, 0.2, 1), + opacity = 1, + weight = 10, + group = "glpoints", + popup = NULL, + ...) { if (is.null(group)) group = deparse(substitute(data)) if (inherits(data, "Spatial")) data <- sf::st_as_sf(data) @@ -256,14 +256,14 @@ addGlifyPointsSrc2 = function(map, ### via attachments -addGlifyPointsFl = function(map, - data, - color = cbind(0, 0.2, 1), - opacity = 1, - weight = 10, - group = "glpoints", - popup = NULL, - ...) { +addGlPointsFl = function(map, + data, + color = cbind(0, 0.2, 1), + opacity = 1, + weight = 10, + group = "glpoints", + popup = NULL, + ...) { if (is.null(group)) group = deparse(substitute(data)) if (inherits(data, "Spatial")) data <- sf::st_as_sf(data) diff --git a/R/glify-polygons.R b/R/glify-polygons.R index 04b4d0b..9eff9dd 100644 --- a/R/glify-polygons.R +++ b/R/glify-polygons.R @@ -8,7 +8,7 @@ #' \dontrun{ #' library(mapview) #' library(leaflet) -#' library(leaflet.glify) +#' library(leafgl) #' library(sf) #' library(colourvalues) #' @@ -20,22 +20,21 @@ #' #' leaflet() %>% #' addProviderTiles(provider = providers$CartoDB.DarkMatter) %>% -#' addGlifyPolygons(data = fran, color = cols) %>% +#' addGlPolygons(data = fran, color = cols) %>% #' addMouseCoordinates() %>% #' setView(lng = 10.5, lat = 49.5, zoom = 8) #' } #' -#' @describeIn addGlifyPoints add polygons to a leaflet map using Leaflet.glify -#' @aliases addGlifyPolygons -#' @export addGlifyPolygons -addGlifyPolygons = function(map, - data, - color = cbind(0, 0.2, 1), - opacity = 0.6, - weight = 10, - group = "glpolygons", - popup = NULL, - ...) { +#' @describeIn addGlPoints add polygons to a leaflet map using Leaflet.glify +#' @aliases addGlPolygons +#' @export addGlPolygons +addGlPolygons = function(map, + data, + color = cbind(0, 0.2, 1), + opacity = 0.6, + group = "glpolygons", + popup = NULL, + ...) { if (is.null(group)) group = deparse(substitute(data)) if (inherits(data, "Spatial")) data <- sf::st_as_sf(data) @@ -68,20 +67,20 @@ addGlifyPolygons = function(map, ) leaflet::invokeMethod(map, leaflet::getMapData(map), 'addGlifyPolygons', - data, cols, popup, opacity, weight, group) + data, cols, popup, opacity, group) } ### via src -addGlifyPolygonsSrc = function(map, - data, - color = cbind(0, 0.2, 1), - opacity = 0.6, - weight = 10, - group = "glpolygons", - popup = NULL, - ...) { +addGlPolygonsSrc = function(map, + data, + color = cbind(0, 0.2, 1), + opacity = 0.6, + weight = 10, + group = "glpolygons", + popup = NULL, + ...) { if (is.null(group)) group = deparse(substitute(data)) if (inherits(data, "Spatial")) data <- sf::st_as_sf(data) @@ -156,14 +155,14 @@ addGlifyPolygonsSrc = function(map, ### via attachments -addGlifyPolygonsFl = function(map, - data, - color = cbind(0, 0.2, 1), - opacity = 0.6, - weight = 10, - group = "glpolygons", - popup = NULL, - ...) { +addGlPolygonsFl = function(map, + data, + color = cbind(0, 0.2, 1), + opacity = 0.6, + weight = 10, + group = "glpolygons", + popup = NULL, + ...) { if (is.null(group)) group = deparse(substitute(data)) if (inherits(data, "Spatial")) data <- sf::st_as_sf(data) @@ -229,6 +228,6 @@ addGlifyPolygonsFl = function(map, # } leaflet::invokeMethod(map, leaflet::getMapData(map), 'addGlifyPolygonsFl', - data_var, color_var, popup, opacity, weight) + data_var, color_var, popup, opacity) } diff --git a/R/glify-shiny.R b/R/glify-shiny.R index ea0bf85..74fc0b5 100644 --- a/R/glify-shiny.R +++ b/R/glify-shiny.R @@ -1,16 +1,16 @@ -#' Use Glify in shiny +#' Use leafgl in shiny #' #' @inheritParams leaflet::leafletOutput #' @importFrom leaflet leafletOutput #' @importFrom htmltools tagList tags -#' @return A UI for rendering Glify +#' @return A UI for rendering leafgl #' @export #' #' @examples #' \dontrun{ #' library(mapview) #' library(leaflet) -#' library(leaflet.glify) +#' library(leafgl) #' library(sf) #' #' n = 1e4 @@ -27,7 +27,7 @@ #' addLayersControl(overlayGroups = "pts") #' #' ui <- fluidPage( -#' glifyOutput("mymap") +#' leafglOutput("mymap") #' ) #' #' server <- function(input, output, session) { @@ -38,7 +38,7 @@ #' } #' -glifyOutput <- function(outputId, width = "100%", height = 400){ +leafglOutput <- function(outputId, width = "100%", height = 400){ tagList( leafletOutput(outputId = outputId, width = width, height = height), tags$script(glifyDependencies()) @@ -47,20 +47,20 @@ glifyOutput <- function(outputId, width = "100%", height = 400){ # Just for consistency # -#' Use Glify in shiny +#' Use leafgl in shiny #' #' @importFrom leaflet renderLeaflet #' #' @inheritParams leaflet::renderLeaflet #' -#' @return A server function for rendering Glify +#' @return A server function for rendering leafgl #' @export #' #' @examples #' \dontrun{ #' library(mapview) #' library(leaflet) -#' library(leaflet.glify) +#' library(leafgl) #' library(sf) #' library(shiny) #' @@ -72,13 +72,13 @@ glifyOutput <- function(outputId, width = "100%", height = 400){ #' #' m = leaflet() %>% #' addProviderTiles(provider = providers$CartoDB.DarkMatter) %>% -#' addGlifyPoints(data = pts, group = "pts") %>% +#' addGlPoints(data = pts, group = "pts") %>% #' addMouseCoordinates() %>% #' setView(lng = 10.5, lat = 49.5, zoom = 6) %>% #' addLayersControl(overlayGroups = "pts") #' #' ui <- fluidPage( -#' glifyOutput("mymap") +#' leafglOutput("mymap") #' ) #' #' server <- function(input, output, session) { @@ -88,7 +88,7 @@ glifyOutput <- function(outputId, width = "100%", height = 400){ #' shinyApp(ui, server) #' } #' -renderGlify <- function(expr, env = parent.frame(), quoted = FALSE){ +renderLeafgl <- function(expr, env = parent.frame(), quoted = FALSE){ renderLeaflet(expr = expr, env = env, quoted = quoted) } diff --git a/README.md b/README.md index f40ed22..4b1c5c0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# leaflet.glify +# leafgl An R package for fast web gl rendering of features on leaflet maps. It's an R port of https://github.com/robertleeplummerjr/Leaflet.glify where @@ -12,7 +12,7 @@ what you get here, make sure to star the original repo! Currently not on CRAN, github only: ```r -devtools::install_github("tim-salabim/leaflet.glify") +devtools::install_github("tim-salabim/leafgl") ``` ### What does it do? @@ -30,7 +30,7 @@ vertices. With regard to 2., obviously the amount of RAM will matter most but there are other, more suptle, problems that can occur. -Given it's name, leaflet.glify is intended to fully integrate with the +Given it's name, leafgl is intended to fully integrate with the leaflet package, though it is very likely that it won't be a 1:1 replacement for the respective `leaflet::add*` functions. For example, given the intention to render/visualise as many features as possible we @@ -58,7 +58,7 @@ implementation. Depending on your operating system and browser, you may see some weird colors that do not correspond to the ones that you specified. The only known work-around at this stage is to set `opacity = 1`. -For more details the inclined reader is referred to [this issue](https://github.com/tim-salabim/leaflet.glify/issues/4) +For more details the inclined reader is referred to [this issue](https://github.com/tim-salabim/leafgl/issues/4) ### What can I do to help? @@ -79,7 +79,7 @@ This will render 1 Mio. points on a standard leaflet map. ```r library(mapview) library(leaflet) -library(leaflet.glify) +library(leafgl) library(sf) n = 1e6 @@ -117,7 +117,7 @@ voctors in the blink of an eye! ```r library(mapview) library(leaflet) -library(leaflet.glify) +library(leafgl) library(sf) library(colourvalues) @@ -159,7 +159,7 @@ This data was downloaded from https://download.geofabrik.de/europe/switzerland.h ```r library(mapview) library(leaflet) -library(leaflet.glify) +library(leafgl) library(sf) library(colourvalues) @@ -194,13 +194,13 @@ m ## Shiny ## -In order to use leaflet.glify in a shiny context, we need to include the +In order to use leafgl in a shiny context, we need to include the necessary javascript dependencies in the ui component. Here's an example: ```r ui <- fluidPage( leafletOutput("mymap"), - tags$script(leaflet.glify:::glifyDependencies()) + tags$script(leafgl:::glifyDependencies()) ) server <- function(input, output, session) { @@ -216,4 +216,4 @@ shinyApp(ui, server) ## Contact ## -Please file Pull requests, bug reports and feature requests at https://github.com/tim-salabim/leaflet.glify/issues +Please file Pull requests, bug reports and feature requests at https://github.com/tim-salabim/leafgl/issues diff --git a/experiments/alabama_glify.R b/experiments/alabama_glify.R index 47240b0..859d8f2 100644 --- a/experiments/alabama_glify.R +++ b/experiments/alabama_glify.R @@ -1,6 +1,6 @@ library(sf) library(mapview) -library(leaflet.glify) +library(leafgl) library(leaflet) library(data.table) @@ -21,11 +21,11 @@ m = mapview()@map %>% ## add each tile embedded via for (i in 1:length(al_lst)) { print(i) - m = leaflet.glify:::addGlifyPolygonsSrc(map = m, - data = al_lst[[i]], - color = cbind(0, 0, 0), - opacity = 0.9, - group = as.character(i)) + m = leafgl:::addGlPolygonsSrc(map = m, + data = al_lst[[i]], + color = cbind(0, 0, 0), + opacity = 0.9, + group = as.character(i)) } ## render in browser rather than viewer diff --git a/experiments/random_markers.R b/experiments/random_markers.R index d23ceb3..0eb8161 100644 --- a/experiments/random_markers.R +++ b/experiments/random_markers.R @@ -1,11 +1,11 @@ library(mapview) library(leaflet) -library(leaflet.glify) +library(leafgl) library(sf) library(colourvalues) library(data.table) -n = 20e6 +n = 2e6 df1 = data.frame(id = 1:n, id2 = n:1, @@ -20,7 +20,7 @@ system.time({ options(viewer = NULL) m = mapview()@map %>% - leaflet.glify:::addGlifyPointsSrc2(data = pts, group = "pts", digits = 5) %>% + leafgl:::addGlPointsSrc2(data = pts, group = "pts", digits = 5) %>% addMouseCoordinates() %>% setView(lng = 10.5, lat = 49.5, zoom = 6) %>% mapview:::updateOverlayGroups(group = "pts") @@ -63,7 +63,7 @@ m = mapview()@map %>% for (i in 1:4) { print(i) - m = leaflet.glify:::addGlifyPointsSrc2(map = m, + m = leafgl:::addGlPointsSrc2(map = m, data = pts_lst[[i]], weight = i * 5, color = cols[i, , drop = FALSE], diff --git a/inst/htmlwidgets/Leaflet.glify/addGlifyPolygons.js b/inst/htmlwidgets/Leaflet.glify/addGlifyPolygons.js index 0b7d1a7..cfcf8e3 100644 --- a/inst/htmlwidgets/Leaflet.glify/addGlifyPolygons.js +++ b/inst/htmlwidgets/Leaflet.glify/addGlifyPolygons.js @@ -1,4 +1,4 @@ -LeafletWidget.methods.addGlifyPolygons = function(data, cols, popup, opacity, size, group) { +LeafletWidget.methods.addGlifyPolygons = function(data, cols, popup, opacity, group) { var map = this; diff --git a/inst/htmlwidgets/Leaflet.glify/addGlifyPolygonsFl.js b/inst/htmlwidgets/Leaflet.glify/addGlifyPolygonsFl.js index c35341b..ede72d9 100644 --- a/inst/htmlwidgets/Leaflet.glify/addGlifyPolygonsFl.js +++ b/inst/htmlwidgets/Leaflet.glify/addGlifyPolygonsFl.js @@ -1,4 +1,4 @@ -LeafletWidget.methods.addGlifyPolygonsFl = function(data_var, color_var, popup_var, opacity, size) { +LeafletWidget.methods.addGlifyPolygonsFl = function(data_var, color_var, popup_var, opacity) { var map = this; var data_fl = document.getElementById(data_var + '-1-attachment' ).href; diff --git a/leaflet.glify.Rproj b/leafgl.Rproj similarity index 100% rename from leaflet.glify.Rproj rename to leafgl.Rproj diff --git a/man/addGlifyPoints.Rd b/man/addGlPoints.Rd similarity index 78% rename from man/addGlifyPoints.Rd rename to man/addGlPoints.Rd index 64319bf..c68f5ed 100644 --- a/man/addGlifyPoints.Rd +++ b/man/addGlPoints.Rd @@ -1,15 +1,15 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/glify-points.R, R/glify-polygons.R -\name{addGlifyPoints} -\alias{addGlifyPoints} -\alias{addGlifyPolygons} +\name{addGlPoints} +\alias{addGlPoints} +\alias{addGlPolygons} \title{add points/polygons to a leaflet map using Leaflet.glify} \usage{ -addGlifyPoints(map, data, color = cbind(0, 0.2, 1), opacity = 1, +addGlPoints(map, data, color = cbind(0, 0.2, 1), opacity = 1, weight = 10, group = "glpoints", popup = NULL, ...) -addGlifyPolygons(map, data, color = cbind(0, 0.2, 1), opacity = 0.6, - weight = 10, group = "glpolygons", popup = NULL, ...) +addGlPolygons(map, data, color = cbind(0, 0.2, 1), opacity = 0.6, + group = "glpolygons", popup = NULL, ...) } \arguments{ \item{map}{a leaflet map to add points/polygons to.} @@ -40,16 +40,16 @@ Multipolygons are currently not supported! Make sure you cast your data } \section{Functions}{ \itemize{ -\item \code{addGlifyPoints}: add points to a leaflet map using Leaflet.glify +\item \code{addGlPoints}: add points to a leaflet map using Leaflet.glify -\item \code{addGlifyPolygons}: add polygons to a leaflet map using Leaflet.glify +\item \code{addGlPolygons}: add polygons to a leaflet map using Leaflet.glify }} \examples{ \dontrun{ library(mapview) library(leaflet) -library(leaflet.glify) +library(leafgl) library(sf) library(colourvalues) library(jsonlite) @@ -68,7 +68,7 @@ options(viewer = NULL) system.time({ m = leaflet() \%>\% addProviderTiles(provider = providers$CartoDB.DarkMatter) \%>\% - addGlifyPoints(data = pts, color = cols, popup = "id") \%>\% + addGlPoints(data = pts, color = cols, popup = "id") \%>\% addMouseCoordinates() \%>\% setView(lng = 10.5, lat = 49.5, zoom = 9) }) @@ -79,7 +79,7 @@ m \dontrun{ library(mapview) library(leaflet) -library(leaflet.glify) +library(leafgl) library(sf) library(colourvalues) @@ -91,7 +91,7 @@ options(viewer = NULL) leaflet() \%>\% addProviderTiles(provider = providers$CartoDB.DarkMatter) \%>\% - addGlifyPolygons(data = fran, color = cols) \%>\% + addGlPolygons(data = fran, color = cols) \%>\% addMouseCoordinates() \%>\% setView(lng = 10.5, lat = 49.5, zoom = 8) } diff --git a/man/glifyOutput.Rd b/man/leafglOutput.Rd similarity index 82% rename from man/glifyOutput.Rd rename to man/leafglOutput.Rd index ad1b0b9..c46617c 100644 --- a/man/glifyOutput.Rd +++ b/man/leafglOutput.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/glify-shiny.R -\name{glifyOutput} -\alias{glifyOutput} -\title{Use Glify in shiny} +\name{leafglOutput} +\alias{leafglOutput} +\title{Use leafgl in shiny} \usage{ -glifyOutput(outputId, width = "100\%", height = 400) +leafglOutput(outputId, width = "100\%", height = 400) } \arguments{ \item{outputId}{output variable to read from} @@ -16,16 +16,16 @@ glifyOutput(outputId, width = "100\%", height = 400) \code{\link[htmlwidgets]{shinyWidgetOutput}})} } \value{ -A UI for rendering Glify +A UI for rendering leafgl } \description{ -Use Glify in shiny +Use leafgl in shiny } \examples{ \dontrun{ library(mapview) library(leaflet) -library(leaflet.glify) +library(leafgl) library(sf) n = 1e4 @@ -42,7 +42,7 @@ m = leaflet() \%>\% addLayersControl(overlayGroups = "pts") ui <- fluidPage( - glifyOutput("mymap") + leafglOutput("mymap") ) server <- function(input, output, session) { diff --git a/man/renderGlify.Rd b/man/renderLeafgl.Rd similarity index 77% rename from man/renderGlify.Rd rename to man/renderLeafgl.Rd index 128b251..efef80b 100644 --- a/man/renderGlify.Rd +++ b/man/renderLeafgl.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/glify-shiny.R -\name{renderGlify} -\alias{renderGlify} -\title{Use Glify in shiny} +\name{renderLeafgl} +\alias{renderLeafgl} +\title{Use leafgl in shiny} \usage{ -renderGlify(expr, env = parent.frame(), quoted = FALSE) +renderLeafgl(expr, env = parent.frame(), quoted = FALSE) } \arguments{ \item{expr}{An expression that generates an HTML widget} @@ -15,16 +15,16 @@ renderGlify(expr, env = parent.frame(), quoted = FALSE) is useful if you want to save an expression in a variable.} } \value{ -A server function for rendering Glify +A server function for rendering leafgl } \description{ -Use Glify in shiny +Use leafgl in shiny } \examples{ \dontrun{ library(mapview) library(leaflet) -library(leaflet.glify) +library(leafgl) library(sf) library(shiny) @@ -36,13 +36,13 @@ pts = st_as_sf(df1, coords = c("x", "y"), crs = 4326) m = leaflet() \%>\% addProviderTiles(provider = providers$CartoDB.DarkMatter) \%>\% - addGlifyPoints(data = pts, group = "pts") \%>\% + addGlPoints(data = pts, group = "pts") \%>\% addMouseCoordinates() \%>\% setView(lng = 10.5, lat = 49.5, zoom = 6) \%>\% addLayersControl(overlayGroups = "pts") ui <- fluidPage( - glifyOutput("mymap") + leafglOutput("mymap") ) server <- function(input, output, session) { diff --git a/tests/testthat.R b/tests/testthat.R index 412a33c..52602d8 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,4 @@ library(testthat) -library(leaflet.glify) +library(leafgl) -test_check("leaflet.glify") +test_check("leafgl") diff --git a/tests/testthat/test-leafgl-addGlPoints.R b/tests/testthat/test-leafgl-addGlPoints.R new file mode 100644 index 0000000..0f02b37 --- /dev/null +++ b/tests/testthat/test-leafgl-addGlPoints.R @@ -0,0 +1,20 @@ +context("test-leafgl-addGlPoints") + +test_that("addGlPoints works", { + library(mapview) + library(leaflet) + library(leafgl) + library(sf) + + n = 1e3 + df1 = data.frame(id = 1:n, + id2 = n:1, + x = rnorm(n, 10, 1), + y = rnorm(n, 49, 0.8)) + pts = st_as_sf(df1, coords = c("x", "y"), crs = 4326) + + m = mapview()@map %>% + addGlPoints(data = pts, group = "pts", digits = 5) + + expect_is(m, "leaflet") +}) diff --git a/tests/testthat/test-leafgl-addGlPolygons.R b/tests/testthat/test-leafgl-addGlPolygons.R new file mode 100644 index 0000000..16e308c --- /dev/null +++ b/tests/testthat/test-leafgl-addGlPolygons.R @@ -0,0 +1,14 @@ +context("test-leafgl-addGlPolygons") + +test_that("addGlPolygons works", { + library(mapview) + library(leaflet) + library(leafgl) + library(sf) + + m = mapview()@map %>% + addGlPolygons(data = suppressWarnings(st_cast(franconia, "POLYGON")), + group = "pls", digits = 5) + + expect_is(m, "leaflet") +}) diff --git a/tests/testthat/test-glify-shiny.R b/tests/testthat/test-leafgl-shiny.R similarity index 67% rename from tests/testthat/test-glify-shiny.R rename to tests/testthat/test-leafgl-shiny.R index 3bae3bb..daf35f8 100644 --- a/tests/testthat/test-glify-shiny.R +++ b/tests/testthat/test-leafgl-shiny.R @@ -1,11 +1,11 @@ -context("test-glify-shiny") +context("test-leafgl-shiny") test_that("shiny works", { - ui <- glifyOutput("mymap") + ui <- leafglOutput("mymap") expect_is(ui, "shiny.tag.list") expect_is(ui, "list") expect_length(ui, 2) - srv <- renderGlify({""}) + srv <- renderLeafgl({""}) expect_is(srv, "shiny.render.function") expect_is(srv, "function") })