forked from libjohn/workshop_flexdashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
12_exercise_crosstalk_map.Rmd
94 lines (64 loc) · 2.38 KB
/
12_exercise_crosstalk_map.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
---
title: "Exercise crosstalk map"
subtitle: "linked brushing with DT & leaflet"
output: html_document
---
In this exercise all the starter code to generate a shared data (linked brushing) plot is provided. Your task is to make the the shared data object and then generate the two plots. Execute the following code. Fill in the code for the final code chunk below.
## 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
Fill in the blank in the code chunk, below. Make a shared data structure with the `map` object generated above. Assign that to a new object: `shared_map`.
```{r}
shared_map <- SharedData$new(___)
```
### Rebuild widgets with shared data
**Make Map**. Fill in the blanks in the code chunk, below. Using the shared data object (`shared_map`), generate your leaflet map again. Assign the new map to a new object name: `shared_leaf_map`
```{r make_map}
shared_leaf_map <- _______ %>%
leaflet(width = "100%") %>%
addTiles() %>%
addMarkers(lat = ~____,
lng = ~____,
popup = ~___)
shared_leaf_map
```
**Make Data Table**. Fill in the blanks in the code chunk, below. Using the shared data object (`shared_map`), generated your DT data table again. Assign the new data table to a new object name: `shared_mapdata_table`
```{r make_datatable}
shared_mapdata_table <- datatable(________, extensions="Scroller",
style="bootstrap",
class="compact",
width="100%",
options=list(deferRender=TRUE, scrollY=300, scroller=TRUE))
shared_mapdata_table
```
## bscols
Place the two objects you generated in the **Make Map** and **Make Data Table** code chunks inside the `bscols` (comma separated). Execute the code chunk. What does `bscols` do?
```{r}
bscols(,)
```