-
Notifications
You must be signed in to change notification settings - Fork 7
/
flexdashboards.Rmd
327 lines (215 loc) · 6.63 KB
/
flexdashboards.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
---
title: "flexdashboard"
subtitle: "Easy interactive dashboards for R"
output:
revealjs::revealjs_presentation:
theme: serif
incremental: yes
transition: slide
css: flexdashboards.css
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Introduction
## Outline
1. What's a dashboard?
2. Dashboard layouts
3. Dashboard components
4. Interactive dashboards
5. flexdashboard vs. shinydashboard
## What's a dashboard?
![dashboard-cartoon](dashboard-cartoon.jpg)
## This is a dashboard
![marketing](marketing-dashboard.png)
## This is a dashboard
![amazon](amazon-dashboard.png)
## This is a dashboard
![social-media](socialmedia-dashboard.png)
## This is not a dashboard
![stanford-baby](stanford-baby.jpg)
## This is a dashboard
![car](car-dashboard.jpg)
## What's a dashboard?
- A communications tool showing relevant information about different aspects of a system
- Full-screen, space-consuming layout
- Often via subdivision
- High-level trends and summaries favored over details
- Information designed for quick, glancing consumption
## Why build one with R?
- Reproducible; bundles analysis with presentation and communication
- Eliminate the middleman; empower analysts to produce executive-grade dashboards
- Virtually infinite customizability
# Introducing flexdashboard
## What is flexdashboard?
- R package designed to produce beautiful dashboards easily
- Built on R Markdown
- Expresses the structure of a dashboard declaratively using Markdown
- Bundles common dashboard user interface components
## Installation
```{r eval=FALSE}
install.packages("flexdashboard", type = "source")
```
# flexdashboard Examples
##
<iframe src="wastelands.html" width="800" height="600">
</iframe>
##
<iframe src="salesreport.html" width="800" height="600">
</iframe>
##
<iframe src="tor.html" width="800" height="600">
</iframe>
# Getting Started
## Via RStudio
![rstudio](rstudio-template.png)
## Via the R prompt
```{r eval=FALSE}
rmarkdown::draft("dashboard.Rmd",
template = "flex_dashboard",
package = "flexdashboard")
```
## YAML header
---
title: "Flex Dashboard"
output: flexdashboard::flex_dashboard
---
# Dashboard Layout
## The Big Idea
- Use Markdown headings to describe the boxes and space division of your dashboard
- Layout is implicit and automatic
- Tweakable with custom attributes
- Content in your boxes fills the box automatically
- Supply gaps between R offerings and common dashboard components
## Level three: boxes.
### This is a box.
This is some text in the box.
![level three](level-three.png)
## Level two: columns
## My first column
### My first box
This is some text in a box.
## My second column
### My second box
This is some slightly different text in a box.
## Level two: columns
![level two](level-two.png)
## Level one: pages
# Page one
### My first box
This is some text in a box.
# Page two
### My second box
This is some slightly different text in a box.
## Level one: pages
![level one](level-one.png)
## Layout Recap:
- flexdashboards are composed of space-filling boxes created with level 3 headers (`###`)
- Boxes can be grouped into columns (or rows, or tabs) with level 2 headers (`##`)
- Pages can group other kinds of components
- Much more advanced layout is possible (see docs for details)
# Components
## Plots and HTML widgets
- Any R graphics are supported
- Graphs and visualizations: the basic building blocks of most dashboards
- Contents automatically scaled to the size of the box
- HTML widgets can include interactivity
## Plots and HTML widgets
### Iris data
```{r, echo = FALSE, results="asis"}
cat(" ```{r}",
" qplot(Sepal.Length, Petal.Length, data = iris, color = Species)",
" ```", sep = "\n")
```
### Birthplace of R
```{r, echo = FALSE, results="asis"}
cat(" ```{r}",
" library(leaflet)",
" m <- leaflet() %>%",
" addTiles() %>% ",
" addMarkers(lng=174.768, lat=-36.852, popup=\"The birthplace of R\")",
" ```",
sep = "\n")
```
## Plots and HTML widgets
![plots-and-widgets](plots-and-widgets.png)
## Value boxes
```{r, eval=FALSE}
library(flexdashboard)
articles <- 204
valueBox(articles,
icon = "fa-pencil",
caption = "Articles per Day")
```
![valuebox](valuebox.png)
## Gauges
```{r, eval=FALSE}
satisfaction <- 86
gauge(satisfaction, min = 0, max = 100, symbol = '%',
label = "Satisfaction", gaugeSectors(
success = c(80, 100), warning = c(40, 79), danger = c(0, 39)
))
```
![gauge](gauge.png)
## Including Data: tabsets
## Column {.tabset}
### Chart
```{r echo=FALSE, results='asis'}
cat(paste(" ```{r}",
" qplot(Sepal.Length, Petal.Length, data = iris, color = Species) ",
" ```", sep = "\n"))
```
### Data
```{r echo=FALSE, results='asis'}
cat(paste(" ```{r}",
" knitr::kable(iris)",
" ```", sep = "\n"))
```
## Including Data: Chart
![chart](tabset-chart.png)
## Including Data: Table
![chart](tabset-data.png)
# Interactive Dashboards
## Interactivity with HTML widgets
- Simplest form of interactivity
- Static HTML; no special client or server requirements
- Host anywhere, view anywhere
- Data must be fixed (can't run R code)
- Interaction within single widget only
- Most widgets don't talk to each other (yet)
## HTML widget interactivity
```{r, eval=FALSE}
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths) %>%
dyRangeSelector()
```
## HTML widget interactivity
```{r, echo=FALSE}
library(dygraphs)
lungDeaths <- cbind(mdeaths, fdeaths)
dygraph(lungDeaths) %>%
dyRangeSelector()
```
## Interactivity with Shiny
- Stream data and update in real time
- More advanced interactivity
- Components can react to each other
- R expressions can be evaluated in response to interaction
- Deployment requires Shiny server or shinyapps.io
## flexdashboard vs. shinydashboard
- Static host vs. Shiny Server (or shinyapps.io)
- Simplicity vs. complexity
- Constraints vs. flexibility
## Advanced topics
- Layout tweaking: adjust column widths/sizes
- Mobile friendliness
- Largely automatic but can show/hide specifically
- Storyboards
- Navigation
# Wrap - up / Q & A
## Links
https://github.com/jmcphers/flexdashboard-talk
- [flexdashboard documentation](http://rmarkdown.rstudio.com/flexdashboard/)
- [HTML widget crosstalk](https://github.com/rstudio/crosstalk)
- [HTML widget showcase](http://www.htmlwidgets.org/showcase_leaflet.html)