-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathREADME.Rmd
134 lines (94 loc) · 3.76 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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.