Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r-spatial/leafpop
Include Tables, Images and Graphs in Leaflet Popups
https://github.com/r-spatial/leafpop
Last synced: 3 months ago
JSON representation
Include Tables, Images and Graphs in Leaflet Popups
- Host: GitHub
- URL: https://github.com/r-spatial/leafpop
- Owner: r-spatial
- License: other
- Created: 2019-04-05T19:14:17.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-14T16:16:28.000Z (over 2 years ago)
- Last Synced: 2024-07-08T12:33:30.873Z (7 months ago)
- Language: R
- Size: 1.81 MB
- Stars: 111
- Watchers: 12
- Forks: 15
- Open Issues: 9
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-leaflet - leafpop: Include Tables, Images and Graphs in Leaflet Popups
- jimsghstars - r-spatial/leafpop - Include Tables, Images and Graphs in Leaflet Popups (R)
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
eval = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# Include Tables, Images and Graphs in Leaflet Popups
[![cran checks](https://cranchecks.info/badges/worst/leafpop)](https://cran.r-project.org/web/checks/check_results_leafpop.html)
[![Travis build status](https://travis-ci.org/r-spatial/leafpop.svg?branch=master)](https://travis-ci.org/r-spatial/leafpop)
[![monthly](http://cranlogs.r-pkg.org/badges/leafpop)](https://www.rpackages.io/package/leafpop)
[![total](http://cranlogs.r-pkg.org/badges/grand-total/leafpop)](https://www.rpackages.io/package/leafpop)
[![CRAN](http://www.r-pkg.org/badges/version/leafpop?color=009999)](https://cran.r-project.org/package=leafpop)
[![status](https://tinyverse.netlify.com/badge/leafpop)](https://CRAN.R-project.org/package=leafpop)`leafpop` 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'.## Installation
You can install the released version of `leafpop` from [CRAN](https://CRAN.R-project.org) with:
```{r, eval=FALSE}
install.packages("leafpop")
```Or the development version from GitHub:
```{r, eval=FALSE}
# install.packages("devtools")
devtools::install_github("r-spatial/leafpop")
```## Examples
#### popupTable
```{r table}
library(leaflet)leaflet() %>%
addTiles() %>%
addCircleMarkers(data = breweries91,
popup = popupTable(breweries91))
```![](man/figures/README-table.png)
#### addPopupImages & popupImage
```{r image}
library(sf)
library(leaflet)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")
```![](man/figures/README-image.png)
Alternatively you can bind the images directly in in the `add*` call, however,
this will not include the images when the map is saved using `mapshot` or
`saveWidget`. This options is basically available for backward compatibility only.```{r image2}
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = pnt, popup = popupImage(img, src = "remote"))
```#### popupGraph
```{r graph}
library(sf)
library(leaflet)
library(lattice)pnt = st_as_sf(data.frame(x = 174.764474, y = -36.877245),
coords = c("x", "y"),
crs = 4326)p2 = levelplot(t(volcano), col.regions = terrain.colors(100))
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = pnt, group = "pnt") %>%
addPopupGraphs(list(p2), group = "pnt", width = 300, height = 400)
```![](man/figures/README-graph.png)
Alternatively you can bind the graphs directly in in the `add*` call, however,
this will not include the graphs when the map is saved using `mapshot` or
`saveWidget`. This options is basically available for backward compatibility only.```{r graph2}
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = pnt, popup = popupGraph(p2, width = 300, height = 400))
```#### Further examples
See the [mapview documentation](https://r-spatial.github.io/mapview/articles/articles/mapview_04-popups.html) for further examples.
### Code of Conduct
Please note that the 'leafpop' project is released with a [Contributor Code of Conduct](https://github.com/r-spatial/leafpop/blob/master/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.