Package 'leafpop'

Title: Include Tables, Images and Graphs in Leaflet Pop-Ups
Description: Creates 'HTML' strings to embed tables, images or graphs in pop-ups of interactive maps created with packages like 'leaflet' or 'mapview'. Handles local images located on the file system or via remote URL. Handles graphs created with 'lattice' or 'ggplot2' as well as interactive plots created with 'htmlwidgets'.
Authors: Tim Appelhans [cre, aut], Florian Detsch [aut]
Maintainer: Tim Appelhans <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-11-18 03:23:27 UTC
Source: https://github.com/r-spatial/leafpop

Help Index


Include Tables, Images and Graphs in Leaflet Popups

Description

Include Tables, Images and Graphs in Leaflet Popups

Details

Creates HTML strings to embed tables, images or graphs in popups of interactive maps created with packages 'leaflet' or 'mapview'. Handles local paths to images on the file system or remote urls. Handles graphs created with 'base' graphics, 'lattice' or 'ggplot2' as well as interactive plots created with 'htmlwidgets'.

Author(s)

Tim Appelhans, Florian Detsch Maintainer: Tim Appelhans [email protected]


Add graph/plot popups to leaflet layers.

Description

Add graph/plot popups to leaflet layers.

Usage

addPopupGraphs(map, graph, group, width = 300, height = 300, ...)

Arguments

map

the leaflet map to add the popups to.

graph

A list of lattice or ggplot2 objects. Needs to be a list, even for a single plot!

group

the map group to which the popups should be added.

width

the width of the graph(s) in pixels.

height

the height of the graph(s) in pixels.

...

additional arguments passed to addPopupImages.

Value

A leaflet map.

Examples

if (interactive()) {
library(sf)
library(leaflet)
library(lattice)

pt = data.frame(x = 174.764474, y = -36.877245)
pt = st_as_sf(pt, coords = c("x", "y"), crs = 4326)

p2 = levelplot(t(volcano), col.regions = terrain.colors(100))

leaflet() %>%
  addTiles() %>%
  addCircleMarkers(data = pt, group = "pt") %>%
  addPopupGraphs(list(p2), group = "pt", width = 300, height = 400)

}

Add image popups to leaflet layers.

Description

Add image popups to leaflet layers.

Usage

addPopupImages(
  map,
  image,
  group,
  width = NULL,
  height = NULL,
  tooltip = FALSE,
  ...
)

Arguments

map

the leaflet map to add the popups to.

image

A character vector of file path(s) or web-URL(s) to any sort of image file(s).

group

the map group to which the popups should be added.

width

the width of the image(s) in pixels.

height

the height of the image(s) in pixels.

tooltip

logical, whether to show image(s) as popup(s) (on click) or tooltip(s) (on hover).

...

additional options passed on to the JavaScript creator function. See https://leafletjs.com/reference-1.7.1.html#popup & https://leafletjs.com/reference-1.7.1.html#tooltip for details.

Value

A leaflet map.

Examples

if (interactive()) {
## remote images -----
### one image
library(leaflet)
library(sf)
library(lattice)

pnt = st_as_sf(data.frame(x = 174.764474, y = -36.877245),
                coords = c("x", "y"),
                crs = 4326)

img = "http://bit.ly/1TVwRiR"

leaflet() %>%
  addTiles() %>%
  addCircleMarkers(data = pnt, group = "pnt") %>%
  addPopupImages(img, group = "pnt")

### multiple file (types)
library(sf)
images = c(img,
            "https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg",
            "https://www.r-project.org/logo/Rlogo.png",
            "https://upload.wikimedia.org/wikipedia/commons/d/d6/MeanMonthlyP.gif")

pt4 = data.frame(x = jitter(rep(174.764474, 4), factor = 0.01),
                  y = jitter(rep(-36.877245, 4), factor = 0.01))
pt4 = st_as_sf(pt4, coords = c("x", "y"), crs = 4326)

leaflet() %>%
  addTiles() %>%
  addMarkers(data = pt4, group = "points") %>%
  addPopupImages(images, group = "points", width = 400) # NOTE the gif animation

## local images -----
pnt = st_as_sf(data.frame(x = 174.764474, y = -36.877245),
                coords = c("x", "y"), crs = 4326)
img = system.file("img","Rlogo.png",package="png")
leaflet() %>%
  addTiles() %>%
  addCircleMarkers(data = pnt, group = "pnt") %>%
  addPopupImages(img, group = "pnt")
}