forked from libjohn/workshop_flexdashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
12_exercise_crosstalk_map_answers.Rmd
87 lines (59 loc) · 1.33 KB
/
12_exercise_crosstalk_map_answers.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
---
title: "Answers -> Exercise crosstalk map"
subtitle: "linked brushing with DT & leaflet"
output: html_document
---
## Library Packages
```{r}
library(tidyverse)
library(leaflet)
library(DT)
library(crosstalk)
```
## Load Data
```{r}
map <- read_csv("data/mockaroo_latlon.csv")
map
```
## Plot Map via Leaflet
```{r}
leaf_map <- map %>%
leaflet(width = "100%") %>%
addTiles() %>%
addMarkers(lat = ~Latitude,
lng = ~Longitude,
popup = ~Company)
leaf_map
```
## DT data table
```{r}
mapdata_table <- datatable(map, extensions="Scroller", style="bootstrap", class="compact", width="100%",
options=list(deferRender=TRUE, scrollY=300, scroller=TRUE))
mapdata_table
```
## Crosstalk
make shared data structure
```{r}
shared_map <- SharedData$new(map)
```
### Rebuild widgets with shared data
Map
```{r}
shared_leaf_map <- shared_map %>%
leaflet(width = "100%") %>%
addTiles() %>%
addMarkers(lat = ~Latitude,
lng = ~Longitude,
popup = ~Company)
shared_leaf_map
```
data table
```{r}
shared_mapdata_table <- datatable(shared_map, extensions="Scroller", style="bootstrap", class="compact", width="100%",
options=list(deferRender=TRUE, scrollY=300, scroller=TRUE))
shared_mapdata_table
```
## bscols
```{r}
bscols(shared_leaf_map, shared_mapdata_table)
```