Skip to content

Commit

Permalink
Merge branch 'main' into pending_calls
Browse files Browse the repository at this point in the history
* main:
  Remove bad test script in package.json
  Use faster versions of system.file()/packageVersion()/is_installed() (#768)
  Patch leaflet.css with missing rule about <img> in pane (#770)
  • Loading branch information
schloerke committed Feb 3, 2022
2 parents 04436dd + 7172358 commit 824e289
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 20 deletions.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FEATURES
BUG FIXES and IMPROVEMENTS
* Enable JS function literals (wrapped in `htmlwidgets::JS()`) to be included in arguments to methods invoked on `leafletProxy` objects. (JS function literals could already be included with methods invoked on `leaflet` objects, so this change just brings `leafletProxy` to parity.) (#420)


* Add missing CSS rule to show `<img>` in right-pane and left-pane (rstudio/rmarkdown/issues#1949).

leaflet 2.0.4.1
--------------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions R/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ addLabelOnlyMarkers <- function(
map = map, lng = lng, lat = lat, layerId = layerId,
group = group,
icon = makeIcon(
iconUrl = system.file("htmlwidgets/lib/rstudio_leaflet/images/1px.png", package = "leaflet"),
iconUrl = system_file("htmlwidgets/lib/rstudio_leaflet/images/1px.png", package = "leaflet"),
iconWidth = 1, iconHeight = 1),
label = label,
labelOptions = labelOptions,
Expand All @@ -707,7 +707,8 @@ markerClusterDependencies <- function() {
htmltools::htmlDependency(
"leaflet-markercluster",
"1.0.5",
system.file("htmlwidgets/plugins/Leaflet.markercluster", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.markercluster",
package = "leaflet",
script = c(
"leaflet.markercluster.js",
"leaflet.markercluster.freezable.js",
Expand Down
2 changes: 1 addition & 1 deletion R/legacy.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ leafletMap <- function(
"contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>"
)

shiny::addResourcePath("leaflet-legacy", system.file("legacy/www", package = "leaflet"))
shiny::addResourcePath("leaflet-legacy", system_file("legacy/www", package = "leaflet"))

if (is.numeric(width))
width <- sprintf("%dpx", width)
Expand Down
12 changes: 8 additions & 4 deletions R/plugin-awesomeMarkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ leafletAwesomeMarkersDependencies <- function() {
htmltools::htmlDependency(
"leaflet-awesomemarkers",
"2.0.3",
system.file("htmlwidgets/plugins/Leaflet.awesome-markers", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.awesome-markers",
package = "leaflet",
script = c("leaflet.awesome-markers.min.js"),
stylesheet = c("leaflet.awesome-markers.css")
)
Expand All @@ -15,7 +16,8 @@ leafletAmBootstrapDependencies <- function(map) {
htmltools::htmlDependency(
"bootstrap",
"3.3.7",
system.file("htmlwidgets/plugins/Leaflet.awesome-markers", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.awesome-markers",
package = "leaflet",
script = c("bootstrap.min.js"),
stylesheet = c("bootstrap.min.css")
)
Expand All @@ -34,7 +36,8 @@ leafletAmFontAwesomeDependencies <- function(map) {
htmltools::htmlDependency(
"fontawesome",
"4.7.0",
system.file("htmlwidgets/plugins/Leaflet.awesome-markers", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.awesome-markers",
package = "leaflet",
stylesheet = c("font-awesome.min.css")
)
)
Expand All @@ -52,7 +55,8 @@ leafletAmIonIconDependencies <- function(map) {
htmltools::htmlDependency(
"ionicons",
"2.0.1",
system.file("htmlwidgets/plugins/Leaflet.awesome-markers", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.awesome-markers",
package = "leaflet",
stylesheet = c("ionicons.min.css")
)
)
Expand Down
3 changes: 2 additions & 1 deletion R/plugin-easybutton.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ leafletEasyButtonDependencies <- function() {
htmltools::htmlDependency(
"leaflet-easybutton",
"1.3.1",
system.file("htmlwidgets/plugins/Leaflet.EasyButton", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.EasyButton",
package = "leaflet",
script = c("easy-button.js", "EasyButton-binding.js"),
stylesheet = c("easy-button.css")
)
Expand Down
3 changes: 2 additions & 1 deletion R/plugin-graticule.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ leafletGraticuleDependencies <- function() {
htmltools::htmlDependency(
"leaflet-graticule",
"0.1.0",
system.file("htmlwidgets/plugins/Leaflet.Graticule", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.Graticule",
package = "leaflet",
script = c("L.Graticule.js", "Graticule-binding.js")
)
)
Expand Down
3 changes: 2 additions & 1 deletion R/plugin-measure.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ leafletMeasureDependencies <- function() {
htmltools::htmlDependency(
"leaflet-measure",
"2.1.7",
system.file("htmlwidgets/lib/leaflet-measure", package = "leaflet"),
"htmlwidgets/lib/leaflet-measure",
package = "leaflet",
script = "leaflet-measure.min.js",
stylesheet = "leaflet-measure.css"
)
Expand Down
3 changes: 2 additions & 1 deletion R/plugin-minimap.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ leafletMiniMapDependencies <- function() {
htmltools::htmlDependency(
"leaflet-minimap",
"3.3.1",
system.file("htmlwidgets/plugins/Leaflet-MiniMap", package = "leaflet"),
"htmlwidgets/plugins/Leaflet-MiniMap",
package = "leaflet",
script = c("Control.MiniMap.min.js", "Minimap-binding.js"),
stylesheet = c("Control.MiniMap.min.css")
)
Expand Down
3 changes: 2 additions & 1 deletion R/plugin-omnivore.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ leafletOmnivoreDependencies <- function() {
htmltools::htmlDependency(
"leaflet-omnivore",
"0.3.3",
system.file("htmlwidgets/lib/leaflet-omnivore", package = "leaflet"),
"htmlwidgets/lib/leaflet-omnivore",
package = "leaflet",
script = "leaflet-omnivore.min.js"
)
)
Expand Down
5 changes: 3 additions & 2 deletions R/plugin-providers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ leafletProviderDependencies <- function() {
get_providers_html_dependency(),
htmltools::htmlDependency(
"leaflet-providers-plugin",
packageVersion("leaflet"),
system.file("htmlwidgets/plugins/leaflet-providers-plugin", package = "leaflet"),
get_package_version("leaflet"),
"htmlwidgets/plugins/leaflet-providers-plugin",
package = "leaflet",
script = "leaflet-providers-plugin.js"
)
)
Expand Down
3 changes: 2 additions & 1 deletion R/plugin-simplegraticule.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ leafletSimpleGraticuleDependencies <- function() {
htmltools::htmlDependency(
"leaflet-simplegraticule",
"0.1.0",
system.file("htmlwidgets/plugins/Leaflet.SimpleGraticule", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.SimpleGraticule",
package = "leaflet",
script = c("L.SimpleGraticule.js", "SimpleGraticule-binding.js"),
stylesheet = "L.SimpleGraticule.css"
)
Expand Down
3 changes: 2 additions & 1 deletion R/plugin-terminator.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ leafletTerminatorDependencies <- function() {
htmltools::htmlDependency(
"leaflet-terminator",
"0.1.0",
system.file("htmlwidgets/plugins/Leaflet.Terminator", package = "leaflet"),
"htmlwidgets/plugins/Leaflet.Terminator",
package = "leaflet",
script = c("L.Terminator.js", "Terminator-binding.js")
)
)
Expand Down
3 changes: 2 additions & 1 deletion R/selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ locationFilter2Dependencies <- function() {
htmltools::htmlDependency(
"leaflet-locationfilter2",
"0.1.1",
system.file("htmlwidgets/plugins/leaflet-locationfilter", package = "leaflet"),
"htmlwidgets/plugins/leaflet-locationfilter",
package = "leaflet",
script = c("locationfilter.js", "locationfilter-bindings.js"),
stylesheet = c("locationfilter.css")
)
Expand Down
107 changes: 107 additions & 0 deletions R/staticimports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Generated by staticimports; do not edit by hand.
# ======================================================================
# Imported from pkg:staticimports
# ======================================================================

# Borrowed from pkgload:::dev_meta, with some modifications.
# Returns TRUE if `pkg` was loaded with `devtools::load_all()`.
devtools_loaded <- function(pkg) {
ns <- .getNamespace(pkg)
if (is.null(ns) || is.null(ns$.__DEVTOOLS__)) {
return(FALSE)
}
TRUE
}

get_package_version <- function(pkg) {
# `utils::packageVersion()` can be slow, so first try the fast path of
# checking if the package is already loaded.
ns <- .getNamespace(pkg)
if (is.null(ns)) {
utils::packageVersion(pkg)
} else {
as.package_version(ns$.__NAMESPACE__.$spec[["version"]])
}
}

is_installed <- function(pkg, version = NULL) {
installed <- isNamespaceLoaded(pkg) || nzchar(system_file_cached(package = pkg))
if (is.null(version)) {
return(installed)
}
installed && isTRUE(get_package_version(pkg) >= version)
}

# Borrowed from pkgload::shim_system.file, with some modifications. This behaves
# like `system.file()`, except that (1) for packages loaded with
# `devtools::load_all()`, it will return the path to files in the package's
# inst/ directory, and (2) for other packages, the directory lookup is cached.
# Also, to keep the implementation simple, it doesn't support specification of
# lib.loc or mustWork.
system_file <- function(..., package = "base") {
if (!devtools_loaded(package)) {
return(system_file_cached(..., package = package))
}

if (!is.null(names(list(...)))) {
stop("All arguments other than `package` must be unnamed.")
}

# If package was loaded with devtools (the package loaded with load_all),
# also search for files under inst/, and don't cache the results (it seems
# more likely that the package path will change during the development
# process)
pkg_path <- find.package(package)

# First look in inst/
files_inst <- file.path(pkg_path, "inst", ...)
present_inst <- file.exists(files_inst)

# For any files that weren't present in inst/, look in the base path
files_top <- file.path(pkg_path, ...)
present_top <- file.exists(files_top)

# Merge them together. Here are the different possible conditions, and the
# desired result. NULL means to drop that element from the result.
#
# files_inst: /inst/A /inst/B /inst/C /inst/D
# present_inst: T T F F
# files_top: /A /B /C /D
# present_top: T F T F
# result: /inst/A /inst/B /C NULL
#
files <- files_top
files[present_inst] <- files_inst[present_inst]
# Drop cases where not present in either location
files <- files[present_inst | present_top]
if (length(files) == 0) {
return("")
}
# Make sure backslashes are replaced with slashes on Windows
normalizePath(files, winslash = "/")
}

# A wrapper for `system.file()`, which caches the results, because
# `system.file()` can be slow. Note that because of caching, if
# `system_file_cached()` is called on a package that isn't installed, then the
# package is installed, and then `system_file_cached()` is called again, it will
# still return "".
system_file_cached <- local({
pkg_dir_cache <- character()

function(..., package = "base") {
if (!is.null(names(list(...)))) {
stop("All arguments other than `package` must be unnamed.")
}

not_cached <- is.na(match(package, names(pkg_dir_cache)))
if (not_cached) {
pkg_dir <- system.file(package = package)
pkg_dir_cache[[package]] <<- pkg_dir
} else {
pkg_dir <- pkg_dir_cache[[package]]
}

file.path(pkg_dir, ...)
}
})
5 changes: 4 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# @staticimports pkg:staticimports
# is_installed system_file get_package_version

# Given a local and/or remote operation and a map, execute one or the other
# depending on the type of the map object (regular or map proxy). If code was
# not provided for the appropriate mode, an error will be raised.
Expand Down Expand Up @@ -210,7 +213,7 @@ invokeRemote <- function(map, method, args = list()) {

sess <- map$session
if (map$deferUntilFlush) {
if (packageVersion("shiny") < "0.12.1.9000") {
if (is_installed("shiny", "0.12.1.9000")) {

# See comment on sessionFlushQueue.

Expand Down
9 changes: 9 additions & 0 deletions inst/htmlwidgets/lib/rstudio_leaflet/rstudio_leaflet.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@
.leaflet-map-pane {
z-index: auto;
}

/* Add missing rule from leaflet for img.
This complete existing leaflet.css.
Fix for https://github.com/rstudio/rmarkdown/issues/1949 */
.leaflet-container .leaflet-right-pane img,
.leaflet-container .leaflet-left-pane img {
max-width: none !important;
max-height: none !important;
}
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/remote.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
[1] "leaflet-calls"

[[1]]$message
{"id":"map","calls":[{"dependencies":[{"name":"leaflet-markercluster","version":"1.0.5","src":{"href":"leaflet-markercluster-1.0.5"},"meta":null,"script":["leaflet.markercluster.js","leaflet.markercluster.freezable.js","leaflet.markercluster.layersupport.js"],"stylesheet":["MarkerCluster.css","MarkerCluster.Default.css"],"head":null,"attachment":null,"package":null,"all_files":true}],"method":"addMarkers","args":[[52.37712,52.37783,52.37755],[4.905167,4.906357,4.905831],null,null,null,{"interactive":true,"draggable":false,"keyboard":true,"title":"","alt":"","zIndexOffset":0,"opacity":1,"riseOnHover":false,"riseOffset":250},null,null,{"showCoverageOnHover":true,"zoomToBoundsOnClick":true,"spiderfyOnMaxZoom":true,"removeOutsideVisibleBounds":true,"spiderLegPolylineOptions":{"weight":1.5,"color":"#222","opacity":0.5},"freezeAtZoom":false,"iconCreateFunction":"function(cluster) {console.log('Here comes cluster',cluster); return new L.DivIcon({html: '<div style=\"background-color:rgba(77,77,77,0.5)\"><span>' + cluster.getChildCount() + '<\/div><span>',className: 'marker-cluster'});}"},null,null,{"interactive":false,"permanent":false,"direction":"auto","opacity":1,"offset":[0,0],"textsize":"10px","textOnly":false,"className":"","sticky":true},null],"evals":["8.iconCreateFunction"]}]}
{"id":"map","calls":[{"dependencies":[{"name":"leaflet-markercluster","version":"1.0.5","src":{"href":"leaflet-markercluster-1.0.5"},"meta":null,"script":["leaflet.markercluster.js","leaflet.markercluster.freezable.js","leaflet.markercluster.layersupport.js"],"stylesheet":["MarkerCluster.css","MarkerCluster.Default.css"],"head":null,"attachment":null,"all_files":true}],"method":"addMarkers","args":[[52.37712,52.37783,52.37755],[4.905167,4.906357,4.905831],null,null,null,{"interactive":true,"draggable":false,"keyboard":true,"title":"","alt":"","zIndexOffset":0,"opacity":1,"riseOnHover":false,"riseOffset":250},null,null,{"showCoverageOnHover":true,"zoomToBoundsOnClick":true,"spiderfyOnMaxZoom":true,"removeOutsideVisibleBounds":true,"spiderLegPolylineOptions":{"weight":1.5,"color":"#222","opacity":0.5},"freezeAtZoom":false,"iconCreateFunction":"function(cluster) {console.log('Here comes cluster',cluster); return new L.DivIcon({html: '<div style=\"background-color:rgba(77,77,77,0.5)\"><span>' + cluster.getChildCount() + '<\/div><span>',className: 'marker-cluster'});}"},null,null,{"interactive":false,"permanent":false,"direction":"auto","opacity":1,"offset":[0,0],"textsize":"10px","textOnly":false,"className":"","sticky":true},null],"evals":["8.iconCreateFunction"]}]}



0 comments on commit 824e289

Please sign in to comment.