-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTutorial-questions.html
773 lines (689 loc) · 48.4 KB
/
Tutorial-questions.html
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="author" content="Giorgio Coppola, Gayatri Shejwal, Lonny Chen" />
<title>Interactive Graphs with Plotly and Dash</title>
<script src="Tutorial-questions_files/header-attrs-2.25/header-attrs.js"></script>
<script src="Tutorial-questions_files/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="Tutorial-questions_files/bootstrap-3.3.5/css/sandstone.min.css" rel="stylesheet" />
<script src="Tutorial-questions_files/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="Tutorial-questions_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="Tutorial-questions_files/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="Tutorial-questions_files/jqueryui-1.13.2/jquery-ui.min.js"></script>
<link href="Tutorial-questions_files/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="Tutorial-questions_files/tocify-1.9.1/jquery.tocify.js"></script>
<script src="Tutorial-questions_files/navigation-1.1/tabsets.js"></script>
<link href="Tutorial-questions_files/pagedtable-1.1/css/pagedtable.css" rel="stylesheet" />
<script src="Tutorial-questions_files/pagedtable-1.1/js/pagedtable.js"></script>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">
code {
white-space: pre;
}
.sourceCode {
overflow: visible;
}
</style>
<style type="text/css" data-origin="pandoc">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ background-color: #f8f8f8; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ef2929; } /* Alert */
code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #204a87; } /* Attribute */
code span.bn { color: #0000cf; } /* BaseN */
code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4e9a06; } /* Char */
code span.cn { color: #8f5902; } /* Constant */
code span.co { color: #8f5902; font-style: italic; } /* Comment */
code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code span.dt { color: #204a87; } /* DataType */
code span.dv { color: #0000cf; } /* DecVal */
code span.er { color: #a40000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #0000cf; } /* Float */
code span.fu { color: #204a87; font-weight: bold; } /* Function */
code span.im { } /* Import */
code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code span.ot { color: #8f5902; } /* Other */
code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code span.sc { color: #ce5c00; font-weight: bold; } /* SpecialChar */
code span.ss { color: #4e9a06; } /* SpecialString */
code span.st { color: #4e9a06; } /* String */
code span.va { color: #000000; } /* Variable */
code span.vs { color: #4e9a06; } /* VerbatimString */
code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
var j = 0;
while (j < rules.length) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
j++;
continue;
}
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') {
j++;
continue;
}
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
}
}
})();
</script>
<link rel="stylesheet" href="custom.css" type="text/css" />
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div id="header">
<h1 class="title toc-ignore">Interactive Graphs with Plotly and
Dash</h1>
<h3 class="subtitle">IDS Workshop on interactive data visualization
Plotly and Dash in R</h3>
<h4 class="author">Giorgio Coppola, Gayatri Shejwal, Lonny Chen</h4>
</div>
<p><br></p>
<p>Data visualization is a powerful mean to understand complex data and
communicate insights effectively, revealing the hidden patterns and
trends that wouldn’t be obvious in tabular data, turning raw data into
information.</p>
<p>The tools we are going to introduce today serve exactly this purpose,
enhancing the visualization possibilities offered by other static
visualization packages such as <code>ggplot2</code>.</p>
<p><strong>What tools allow to do so?</strong></p>
<p>Plotly and Dash! And we will introduce both!</p>
<p>Indeed, <code>plotly</code> and <code>dash</code> are interactive, in
the sense that the user can interact with the data through the graph
directly. This allows possibilities for higher understanding of the
data.</p>
<div id="why-interactive-graphs" class="section level3">
<h3>Why interactive graphs?</h3>
<ul>
<li><p><em>Engagement</em>: Makes data come alive (interactive) and is
more engaging for users. This increase understanding and
retention.</p></li>
<li><p><em>Depth</em>: Allows users to drill down and explore nuances,
as interaction allows to create narratives more easily. Users can ask
‘why’ and get answers instantly by exploring the chart or
graph.</p></li>
<li><p><em>Decision-making</em>: Facilitates more informed
decisions.</p></li>
</ul>
<p>Both <code>plotly</code> and <code>dash</code> are interactive, but
we can say that the level of interaction is different:
<code>plotly</code> appears very similar to a static plot, with the
difference that we can hover your cursor over it, accessing further
data. <code>dash</code> on the other hand, creates proper dashboards,
namely HTML apps, allowing even more interaction.</p>
</div>
<div id="plotly" class="section level1">
<h1>Plotly</h1>
<div id="what-is-plotly" class="section level3">
<h3>What is Plotly?</h3>
<p>Plotly is actually a company headquartered in Montreal, Canada,
providing online graphing, analytics, and statistics tools, as well as
scientific graphing libraries for Python, R, MATLAB, Perl, Julia,
Arduino, JavaScript and REST.</p>
<p>In this context, with Plotly we refer to the R package for to create
interactive graphs.</p>
</div>
<div id="advantages-of-using-plotly" class="section level3">
<h3>Advantages of using Plotly</h3>
<ul>
<li><p>Seamless integration with R and <code>ggplot2</code>, through the
<code>ggplotly()</code> function, that converts your static plots to an
interactive web-based version!</p></li>
<li><p>Diverse range of plots and customization (wide array of chart
types with extensive customization options), as well as the possibility
to zoom in and out into the plot, or select a certain part of the plot
and explore it specifically.</p></li>
<li><p>HTML web integration of graphs, makes visualization more
accessible and intuitive.</p></li>
</ul>
</div>
<div id="lets-see-some-examples-and-exercises" class="section level3">
<h3>Let’s see some examples and exercises</h3>
<p>Many people are surprised that one is required to pay for using the
public toilets in Berlin. Let’s find out how far you would need to go to
use a free toilet after a couple of beers with your friends.</p>
<p><br></p>
</div>
<div id="first-a-nice-barplot" class="section level3">
<h3>First: a nice barplot!</h3>
<p>Let’s use this dataset for the public toilets in Berlin: <a
href="https://www.kaggle.com/datasets/ryanjt/berlin-public-toilets-location/">Berlin
Public Toilet Data</a> database.</p>
<p><br></p>
<p><strong>Q.1.</strong> Find out the district-wise distribution of
public toilets across Berlin.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="co">#1. Prepare data</span></span>
<span id="cb1-2"><a href="#cb1-2" tabindex="-1"></a>toilets <span class="ot"><-</span> <span class="fu">read.csv</span>(<span class="st">"./data/berliner-toiletten-standorte.csv"</span>)</span>
<span id="cb1-3"><a href="#cb1-3" tabindex="-1"></a></span>
<span id="cb1-4"><a href="#cb1-4" tabindex="-1"></a><span class="fu">str</span>(toilets) <span class="co">#tibble</span></span></code></pre></div>
<pre><code>## 'data.frame': 440 obs. of 18 variables:
## $ LavatoryID : chr "Wall_101003" "Wall_112911" "Wall_115753" "Wall_116738" ...
## $ Description : chr "Toilette Ottmachauer Steig (oberhalb Badestelle Ostufer)" "Toilette Uferweg " "Toilette Am Kiesteich 50" "Wall CT, Hubertusdamm" ...
## $ City : chr "Berlin" "Berlin" "Berlin" "Berlin" ...
## $ Street : chr "Krumme Lanke, Quermatenweg (0-24 Uhr)" "Schlachtensee , Am Schlachtensee ggü. 145 (0-24 Uhr)" "Spektepark (0-24 Uhr)" "Hubertusdamm ggü. 7 (0-24 Uhr)" ...
## $ PostalCode : chr "14109" "14129" "13589" "13125" ...
## $ Country : chr "Deutschland" "Deutschland" "Deutschland" "Deutschland" ...
## $ Longitude : num 13.2 13.2 13.2 13.5 13.2 ...
## $ Latitude : num 52.5 52.4 52.5 52.6 52.5 ...
## $ isOwnedByWall : int 1 1 1 1 1 1 1 1 1 1 ...
## $ isHandicappedAccessible: int 0 0 0 1 1 1 1 1 1 1 ...
## $ Price : num 0 0 0 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
## $ canBePayedWithCoins : int 0 0 0 1 1 1 1 1 1 1 ...
## $ canBePayedInApp : int 0 0 0 1 1 1 1 1 1 1 ...
## $ canBePayedWithNFC : int 0 0 0 1 1 1 1 1 1 1 ...
## $ hasChangingTable : int 0 0 0 1 1 1 0 0 1 1 ...
## $ LabelID : int 5 5 5 1 1 1 1 1 1 1 ...
## $ hasUrinal : int 0 0 0 1 0 0 0 1 1 1 ...
## $ FID : int 269 NA NA 868 738 790 716 674 671 684 ...</code></pre>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" tabindex="-1"></a>toilets <span class="ot"><-</span> toilets <span class="sc">|></span></span>
<span id="cb3-2"><a href="#cb3-2" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Free =</span> <span class="fu">if_else</span>(Price <span class="sc">==</span> <span class="dv">0</span>, <span class="st">"free"</span>, <span class="st">"paid"</span>))</span>
<span id="cb3-3"><a href="#cb3-3" tabindex="-1"></a></span>
<span id="cb3-4"><a href="#cb3-4" tabindex="-1"></a><span class="co">#Filter the districts based on postal codes:</span></span>
<span id="cb3-5"><a href="#cb3-5" tabindex="-1"></a></span>
<span id="cb3-6"><a href="#cb3-6" tabindex="-1"></a><span class="co">#Sources</span></span>
<span id="cb3-7"><a href="#cb3-7" tabindex="-1"></a><span class="co">#1. Wikipedia - https://simple.wikipedia.org/wiki/Postal_codes_in_Germany</span></span>
<span id="cb3-8"><a href="#cb3-8" tabindex="-1"></a><span class="co">#2. Cybo - https://postal-codes.cybo.com/germany/berlin/</span></span>
<span id="cb3-9"><a href="#cb3-9" tabindex="-1"></a></span>
<span id="cb3-10"><a href="#cb3-10" tabindex="-1"></a>toilets <span class="ot"><-</span> toilets <span class="sc">|></span></span>
<span id="cb3-11"><a href="#cb3-11" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">District =</span> <span class="fu">case_when</span>(</span>
<span id="cb3-12"><a href="#cb3-12" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10115</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10179</span>) <span class="sc">|</span> </span>
<span id="cb3-13"><a href="#cb3-13" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">13347</span> <span class="sc">&</span>PostalCode <span class="sc"><=</span> <span class="dv">13359</span>) <span class="sc">~</span> <span class="st">"Mitte"</span>,</span>
<span id="cb3-14"><a href="#cb3-14" tabindex="-1"></a> </span>
<span id="cb3-15"><a href="#cb3-15" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10179</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10249</span>) <span class="sc">|</span></span>
<span id="cb3-16"><a href="#cb3-16" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10961</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10999</span>) <span class="sc">~</span> <span class="st">"Friedrichshain-Kreuzberg"</span>,</span>
<span id="cb3-17"><a href="#cb3-17" tabindex="-1"></a> </span>
<span id="cb3-18"><a href="#cb3-18" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10367</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10407</span>) <span class="sc">|</span> </span>
<span id="cb3-19"><a href="#cb3-19" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10318</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10319</span>) <span class="sc">~</span> <span class="st">"Lichtenberg"</span>,</span>
<span id="cb3-20"><a href="#cb3-20" tabindex="-1"></a> </span>
<span id="cb3-21"><a href="#cb3-21" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10405</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10439</span>) <span class="sc">|</span> </span>
<span id="cb3-22"><a href="#cb3-22" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">13086</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">13129</span>) <span class="sc">~</span> <span class="st">"Pankow"</span>,</span>
<span id="cb3-23"><a href="#cb3-23" tabindex="-1"></a> </span>
<span id="cb3-24"><a href="#cb3-24" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10585</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10779</span>) <span class="sc">|</span> </span>
<span id="cb3-25"><a href="#cb3-25" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12159</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12163</span>) <span class="sc">|</span> </span>
<span id="cb3-26"><a href="#cb3-26" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">13629</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">14053</span>) <span class="sc">~</span> <span class="st">"Charlottenburg-Wilmersdorf"</span>,</span>
<span id="cb3-27"><a href="#cb3-27" tabindex="-1"></a> </span>
<span id="cb3-28"><a href="#cb3-28" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12099</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12109</span>) <span class="sc">|</span> </span>
<span id="cb3-29"><a href="#cb3-29" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10777</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10783</span>) <span class="sc">|</span> </span>
<span id="cb3-30"><a href="#cb3-30" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10823</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">10829</span>) <span class="sc">|</span> </span>
<span id="cb3-31"><a href="#cb3-31" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12305</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12309</span>) <span class="sc">|</span> </span>
<span id="cb3-32"><a href="#cb3-32" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12277</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12279</span>) <span class="sc">~</span> <span class="st">"Tempelhof-Schöneberg"</span>,</span>
<span id="cb3-33"><a href="#cb3-33" tabindex="-1"></a> </span>
<span id="cb3-34"><a href="#cb3-34" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">10999</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12059</span>) <span class="sc">|</span> </span>
<span id="cb3-35"><a href="#cb3-35" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12555</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12559</span>) <span class="sc">|</span> </span>
<span id="cb3-36"><a href="#cb3-36" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12487</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12489</span>) <span class="sc">~</span> <span class="st">"Treptow-Köpenick"</span>,</span>
<span id="cb3-37"><a href="#cb3-37" tabindex="-1"></a> </span>
<span id="cb3-38"><a href="#cb3-38" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12163</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12169</span>) <span class="sc">|</span> </span>
<span id="cb3-39"><a href="#cb3-39" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">14163</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">14169</span>) <span class="sc">|</span> </span>
<span id="cb3-40"><a href="#cb3-40" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12203</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12209</span>) <span class="sc">|</span> </span>
<span id="cb3-41"><a href="#cb3-41" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12247</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12249</span>) <span class="sc">|</span> </span>
<span id="cb3-42"><a href="#cb3-42" tabindex="-1"></a> (PostalCode <span class="sc">==</span> <span class="dv">14109</span>) <span class="sc">~</span> <span class="st">"Steglitz-Zehlendorf"</span>,</span>
<span id="cb3-43"><a href="#cb3-43" tabindex="-1"></a> </span>
<span id="cb3-44"><a href="#cb3-44" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">13407</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">13439</span>) <span class="sc">|</span> </span>
<span id="cb3-45"><a href="#cb3-45" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">13505</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">13509</span>) <span class="sc">~</span> <span class="st">"Reinickendorf"</span>,</span>
<span id="cb3-46"><a href="#cb3-46" tabindex="-1"></a> </span>
<span id="cb3-47"><a href="#cb3-47" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12043</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12059</span>) <span class="sc">~</span> <span class="st">"Neukölln"</span>,</span>
<span id="cb3-48"><a href="#cb3-48" tabindex="-1"></a> </span>
<span id="cb3-49"><a href="#cb3-49" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">12679</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">12689</span>) <span class="sc">~</span> <span class="st">"Marzahn-Hellersdorf"</span>,</span>
<span id="cb3-50"><a href="#cb3-50" tabindex="-1"></a> </span>
<span id="cb3-51"><a href="#cb3-51" tabindex="-1"></a> (PostalCode <span class="sc">>=</span> <span class="dv">13599</span> <span class="sc">&</span> PostalCode <span class="sc"><=</span> <span class="dv">13629</span> <span class="sc">~</span> <span class="st">"Spandau"</span>)</span>
<span id="cb3-52"><a href="#cb3-52" tabindex="-1"></a> ))</span></code></pre></div>
</div>
<div id="put-you-answer-here" class="section level2">
<h2>Put you answer here:</h2>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="co">#Plot the distribution using plotly:</span></span></code></pre></div>
<p><strong>Q.2.</strong> Can you comment on the number of free toilets
vs. paid public toilets across Berlin? Based on this dataset, which
district in Berlin has the highest and lowest number of free public
toilets?</p>
<div id="second-ggplotly" class="section level3">
<h3>Second: ggplotly!</h3>
<p><strong>Q.3.</strong> Using the ‘beers’ dataset, use ggplot to
generate a parallel coordinates plot for the first 20 beers. Then
transform the ggplot to a interactive plot using ggplotly. (Hint: Use
package “GGally” to generate a parallel coordinates plot. Beware of
NA’s!)</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a>beers_original <span class="ot"><-</span> <span class="fu">read.csv</span>(<span class="st">"./data/beers.csv"</span>)</span>
<span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a></span>
<span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a>beers_test <span class="ot"><-</span> beers_original <span class="sc">|></span></span>
<span id="cb5-4"><a href="#cb5-4" tabindex="-1"></a> <span class="fu">filter</span>(ibu <span class="sc">!=</span> <span class="st">"NA"</span>) <span class="sc">|></span></span>
<span id="cb5-5"><a href="#cb5-5" tabindex="-1"></a> <span class="fu">slice</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">20</span>)</span>
<span id="cb5-6"><a href="#cb5-6" tabindex="-1"></a></span>
<span id="cb5-7"><a href="#cb5-7" tabindex="-1"></a><span class="co"># Put your answer here:</span></span></code></pre></div>
</div>
<div id="third-a-bubble-chart" class="section level3">
<h3>Third: A bubble chart!</h3>
<p>Try to code a bubble chart according to these instructions: - The
x-axis represents the abv (alcohol by volume). - The y-axis represents
the average_ibu (average bitterness level) for each combination of
style_group and abv. - The size of each bubble is determined by the
number of beers (count) that fall into each combination of style_group
and abv. - The color of the bubbles is determined by the style_group. -
Use the plot_ly function to create the bubble chart with data from
agg_data_2. - Try to determine the size of the bubbles by the count
column of agg_data_2, with sizes ranging from 10 to 800. - Determine the
color of the bubbles by the style_group column, with colors taken from
the “Set1” color palette. - Hover text for each bubble using the paste
function, showing details about style_group, abv, and average_ibu. - Use
the layout function to set the chart title, axis titles, and other
visualization properties. - Add the number of beers for each combination
as a hovertext for each bubble.</p>
<p>Use the following data:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="co"># Create the bubble chart</span></span>
<span id="cb6-2"><a href="#cb6-2" tabindex="-1"></a>beers <span class="ot"><-</span> beers_original <span class="sc">|></span></span>
<span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">style_group =</span> <span class="fu">case_when</span>(</span>
<span id="cb6-4"><a href="#cb6-4" tabindex="-1"></a> (<span class="fu">str_detect</span>(style, <span class="st">"IPA"</span>) <span class="sc">~</span> <span class="st">"IPA"</span>),</span>
<span id="cb6-5"><a href="#cb6-5" tabindex="-1"></a> (<span class="fu">str_detect</span>(style, <span class="st">"Ale"</span>) <span class="sc">~</span> <span class="st">"Ale"</span>),</span>
<span id="cb6-6"><a href="#cb6-6" tabindex="-1"></a> (<span class="fu">str_detect</span>(style, <span class="st">"Lager"</span>) <span class="sc">|</span> style <span class="sc">==</span> <span class="st">"Altbier"</span> <span class="sc">~</span> <span class="st">"Lager"</span>),</span>
<span id="cb6-7"><a href="#cb6-7" tabindex="-1"></a> (<span class="fu">str_detect</span>(style, <span class="st">"Pilsner"</span>) <span class="sc">|</span> <span class="fu">str_detect</span>(style, <span class="st">"Pilsener"</span>) <span class="sc">~</span> <span class="st">"Pilsner"</span>),</span>
<span id="cb6-8"><a href="#cb6-8" tabindex="-1"></a> (<span class="fu">str_detect</span>(style, <span class="st">"Stout"</span>) <span class="sc">~</span> <span class="st">"Stout"</span>),</span>
<span id="cb6-9"><a href="#cb6-9" tabindex="-1"></a> (<span class="fu">str_detect</span>(style, <span class="st">"Barleywine"</span>) <span class="sc">~</span> <span class="st">"Barleywine"</span>),</span>
<span id="cb6-10"><a href="#cb6-10" tabindex="-1"></a> (<span class="fu">str_detect</span>(style, <span class="st">"Porter"</span>) <span class="sc">~</span> <span class="st">"Porter"</span>),</span>
<span id="cb6-11"><a href="#cb6-11" tabindex="-1"></a> (<span class="fu">str_detect</span>(style, <span class="st">"Radler"</span>) <span class="sc">|</span> <span class="fu">str_detect</span>(style, <span class="st">"Fruit"</span>) <span class="sc">~</span> <span class="st">"Radler/Fruit"</span>),</span>
<span id="cb6-12"><a href="#cb6-12" tabindex="-1"></a> <span class="at">.default =</span> <span class="st">"Other"</span></span>
<span id="cb6-13"><a href="#cb6-13" tabindex="-1"></a> )</span>
<span id="cb6-14"><a href="#cb6-14" tabindex="-1"></a> )</span>
<span id="cb6-15"><a href="#cb6-15" tabindex="-1"></a></span>
<span id="cb6-16"><a href="#cb6-16" tabindex="-1"></a>agg_data_2 <span class="ot"><-</span> beers <span class="sc">%>%</span></span>
<span id="cb6-17"><a href="#cb6-17" tabindex="-1"></a> <span class="fu">group_by</span>(style_group, abv) <span class="sc">%>%</span></span>
<span id="cb6-18"><a href="#cb6-18" tabindex="-1"></a> <span class="fu">summarise</span>(</span>
<span id="cb6-19"><a href="#cb6-19" tabindex="-1"></a> <span class="at">average_ibu =</span> <span class="fu">mean</span>(ibu, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb6-20"><a href="#cb6-20" tabindex="-1"></a> <span class="at">count =</span> <span class="fu">n</span>()</span>
<span id="cb6-21"><a href="#cb6-21" tabindex="-1"></a> )</span></code></pre></div>
</div>
</div>
<div id="put-you-answer-here-1" class="section level2">
<h2>Put you answer here:</h2>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" tabindex="-1"></a><span class="co"># Create the bubble chart </span></span></code></pre></div>
<p><br></p>
</div>
</div>
<div id="dash" class="section level1">
<h1>Dash</h1>
<div id="what-is-dash" class="section level3">
<h3>What is Dash?</h3>
<p>A web application framework for R (and Python and other programming
languages) that allows creating interactive, web-based data dashboards
(indeed), turning your interactive plots into full-blown web
applications.</p>
</div>
<div id="key-features" class="section level3">
<h3>Key features</h3>
<ul>
<li><p><strong>HTML layout</strong>: Design your dashboard layout using
simple HTML components, without having to write any actual HTML. Indeed,
it structure dashboard components using a set of pre-defined HTML tags
within R.</p></li>
<li><p>Interactivity through <strong>callbacks</strong>: callbacks
define interactive behavior by specifying how input changes should
modify output components. Essentially, when changing a dropdown or move
a slider, a callback updates a chart, text, or any other component in
real-time.</p></li>
<li><p><strong>Integration with Plotly</strong> visualizations: Plotly
charts can be easily included in Dash, making them part of an<br />
interactive dashboard where each component can talk to others.</p></li>
</ul>
</div>
<div id="some-visualization-examples." class="section level3">
<h3>Some visualization examples.</h3>
<p>We will use the same toilets dataset.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" tabindex="-1"></a>app <span class="ot"><-</span> <span class="fu">dash_app</span>()</span></code></pre></div>
<p>We mutate the table to add the columns for any specific filters that
we require.</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" tabindex="-1"></a>toilets <span class="ot"><-</span> toilets <span class="sc">|></span></span>
<span id="cb9-2"><a href="#cb9-2" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Accessibility =</span> <span class="fu">if_else</span>(isHandicappedAccessible <span class="sc">==</span> <span class="dv">0</span>, <span class="st">"Handicapped Accessible"</span>, <span class="st">"Not Handicapped Accessible"</span>)) <span class="sc">|></span></span>
<span id="cb9-3"><a href="#cb9-3" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">BabyFacilities =</span> <span class="fu">if_else</span>(hasChangingTable <span class="sc">==</span> <span class="dv">0</span>, <span class="st">"Changing table"</span>, <span class="st">"No changing table"</span>))</span></code></pre></div>
<p>We would like to see the distribution of the toilets across Berlin,
based on whether they are paid or not.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" tabindex="-1"></a><span class="co">#We assign different colours to different districts.</span></span>
<span id="cb10-2"><a href="#cb10-2" tabindex="-1"></a>color_options <span class="ot"><-</span> <span class="fu">c</span>(<span class="fu">unique</span>(toilets<span class="sc">$</span>District))</span>
<span id="cb10-3"><a href="#cb10-3" tabindex="-1"></a></span>
<span id="cb10-4"><a href="#cb10-4" tabindex="-1"></a><span class="co">#We filter the toilets based on whether they are free or paid.</span></span>
<span id="cb10-5"><a href="#cb10-5" tabindex="-1"></a>price_options <span class="ot"><-</span> <span class="fu">c</span>(<span class="fu">unique</span>(toilets<span class="sc">$</span>Free))</span>
<span id="cb10-6"><a href="#cb10-6" tabindex="-1"></a>price_filter <span class="ot"><-</span> <span class="fu">dccChecklist</span>(</span>
<span id="cb10-7"><a href="#cb10-7" tabindex="-1"></a> <span class="at">id =</span> <span class="st">'price-filter'</span>,</span>
<span id="cb10-8"><a href="#cb10-8" tabindex="-1"></a> <span class="at">options =</span> price_options,</span>
<span id="cb10-9"><a href="#cb10-9" tabindex="-1"></a> <span class="at">value =</span> price_options <span class="co">#default, choose all</span></span>
<span id="cb10-10"><a href="#cb10-10" tabindex="-1"></a>)</span>
<span id="cb10-11"><a href="#cb10-11" tabindex="-1"></a></span>
<span id="cb10-12"><a href="#cb10-12" tabindex="-1"></a><span class="co">#We can also add additional filters like accessibility for the handicapped and child facilities:</span></span>
<span id="cb10-13"><a href="#cb10-13" tabindex="-1"></a></span>
<span id="cb10-14"><a href="#cb10-14" tabindex="-1"></a>handicap_options <span class="ot"><-</span> <span class="fu">c</span>(<span class="fu">unique</span>(toilets<span class="sc">$</span>Accessibility))</span>
<span id="cb10-15"><a href="#cb10-15" tabindex="-1"></a>handicap_filter <span class="ot"><-</span> <span class="fu">dccChecklist</span>(</span>
<span id="cb10-16"><a href="#cb10-16" tabindex="-1"></a> <span class="at">id =</span> <span class="st">'handicap-filter'</span>,</span>
<span id="cb10-17"><a href="#cb10-17" tabindex="-1"></a> <span class="at">options =</span> handicap_options,</span>
<span id="cb10-18"><a href="#cb10-18" tabindex="-1"></a> <span class="at">value =</span> handicap_options <span class="co">#default, choose all</span></span>
<span id="cb10-19"><a href="#cb10-19" tabindex="-1"></a>)</span>
<span id="cb10-20"><a href="#cb10-20" tabindex="-1"></a></span>
<span id="cb10-21"><a href="#cb10-21" tabindex="-1"></a>baby_options <span class="ot"><-</span> <span class="fu">c</span>(<span class="fu">unique</span>(toilets<span class="sc">$</span>BabyFacilities))</span>
<span id="cb10-22"><a href="#cb10-22" tabindex="-1"></a>baby_filter <span class="ot"><-</span> <span class="fu">dccChecklist</span>(</span>
<span id="cb10-23"><a href="#cb10-23" tabindex="-1"></a> <span class="at">id =</span> <span class="st">'baby-filter'</span>,</span>
<span id="cb10-24"><a href="#cb10-24" tabindex="-1"></a> <span class="at">options =</span> baby_options,</span>
<span id="cb10-25"><a href="#cb10-25" tabindex="-1"></a> <span class="at">value =</span> baby_options <span class="co">#default, choose all</span></span>
<span id="cb10-26"><a href="#cb10-26" tabindex="-1"></a>)</span></code></pre></div>
<p>We assign the graph to a new variable and give instructions for
callback based on the input(s) we provided.</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" tabindex="-1"></a><span class="co">#Output component(s)</span></span>
<span id="cb11-2"><a href="#cb11-2" tabindex="-1"></a>toilets_map <span class="ot"><-</span> <span class="fu">dccGraph</span>(<span class="at">id =</span> <span class="st">'toilets-map'</span>)</span>
<span id="cb11-3"><a href="#cb11-3" tabindex="-1"></a></span>
<span id="cb11-4"><a href="#cb11-4" tabindex="-1"></a><span class="co">#Callback(s)</span></span>
<span id="cb11-5"><a href="#cb11-5" tabindex="-1"></a>app <span class="sc">|></span> <span class="fu">add_callback</span>(</span>
<span id="cb11-6"><a href="#cb11-6" tabindex="-1"></a> <span class="fu">output</span>(<span class="st">'toilets-map'</span>, <span class="st">'figure'</span>),</span>
<span id="cb11-7"><a href="#cb11-7" tabindex="-1"></a> <span class="fu">list</span>(</span>
<span id="cb11-8"><a href="#cb11-8" tabindex="-1"></a> <span class="co">#input('district-dropdown', 'value'),</span></span>
<span id="cb11-9"><a href="#cb11-9" tabindex="-1"></a> <span class="fu">input</span>(<span class="st">'price-filter'</span>, <span class="st">'value'</span>),</span>
<span id="cb11-10"><a href="#cb11-10" tabindex="-1"></a> <span class="fu">input</span>(<span class="st">'handicap-filter'</span>, <span class="st">'value'</span>),</span>
<span id="cb11-11"><a href="#cb11-11" tabindex="-1"></a> <span class="fu">input</span>(<span class="st">'baby-filter'</span>, <span class="st">'value'</span>)</span>
<span id="cb11-12"><a href="#cb11-12" tabindex="-1"></a> ),</span>
<span id="cb11-13"><a href="#cb11-13" tabindex="-1"></a> <span class="cf">function</span>(price_input, handicap_input, baby_input) { <span class="co">#district_input</span></span>
<span id="cb11-14"><a href="#cb11-14" tabindex="-1"></a> <span class="co">#function(color_input) {</span></span>
<span id="cb11-15"><a href="#cb11-15" tabindex="-1"></a> toilets <span class="ot"><-</span> toilets <span class="sc">|></span></span>
<span id="cb11-16"><a href="#cb11-16" tabindex="-1"></a> <span class="fu">filter</span>(Free <span class="sc">%in%</span> price_input) <span class="sc">|></span></span>
<span id="cb11-17"><a href="#cb11-17" tabindex="-1"></a> <span class="fu">filter</span>(Accessibility <span class="sc">%in%</span> handicap_input) <span class="sc">|></span></span>
<span id="cb11-18"><a href="#cb11-18" tabindex="-1"></a> <span class="fu">filter</span>(BabyFacilities <span class="sc">%in%</span> baby_input)</span>
<span id="cb11-19"><a href="#cb11-19" tabindex="-1"></a> fig <span class="ot">=</span> toilets <span class="sc">|></span></span>
<span id="cb11-20"><a href="#cb11-20" tabindex="-1"></a> <span class="fu">filter</span>(District <span class="sc">!=</span> <span class="st">"NA"</span>) <span class="sc">|></span></span>
<span id="cb11-21"><a href="#cb11-21" tabindex="-1"></a> <span class="fu">plot_ly</span>(<span class="at">lat =</span> <span class="sc">~</span>Latitude, <span class="at">lon =</span> <span class="sc">~</span>Longitude, <span class="at">type =</span> <span class="st">"scattermapbox"</span>,</span>
<span id="cb11-22"><a href="#cb11-22" tabindex="-1"></a> <span class="at">split =</span> <span class="sc">~</span>District, <span class="at">size =</span> <span class="dv">5</span>, <span class="co">#toilets[[color_input]]</span></span>
<span id="cb11-23"><a href="#cb11-23" tabindex="-1"></a> <span class="at">hoverinfo =</span> <span class="st">"text+name"</span>, <span class="at">hovertext =</span> <span class="sc">~</span>Street) <span class="sc">|></span></span>
<span id="cb11-24"><a href="#cb11-24" tabindex="-1"></a> <span class="fu">layout</span>(</span>
<span id="cb11-25"><a href="#cb11-25" tabindex="-1"></a> <span class="at">title =</span> <span class="st">"Berlin public toilets"</span>,</span>
<span id="cb11-26"><a href="#cb11-26" tabindex="-1"></a> <span class="at">mapbox =</span> <span class="fu">list</span>(</span>
<span id="cb11-27"><a href="#cb11-27" tabindex="-1"></a> <span class="at">style =</span> <span class="st">'open-street-map'</span>,</span>
<span id="cb11-28"><a href="#cb11-28" tabindex="-1"></a> <span class="at">zoom =</span> <span class="dv">10</span>,</span>
<span id="cb11-29"><a href="#cb11-29" tabindex="-1"></a> <span class="at">center =</span> <span class="fu">list</span>(<span class="at">lat =</span> <span class="sc">~</span><span class="fu">median</span>(Latitude), <span class="at">lon =</span> <span class="sc">~</span><span class="fu">median</span>(Longitude)))</span>
<span id="cb11-30"><a href="#cb11-30" tabindex="-1"></a> )</span>
<span id="cb11-31"><a href="#cb11-31" tabindex="-1"></a> <span class="fu">return</span>(fig) <span class="co">#not needed but just to be explicit</span></span>
<span id="cb11-32"><a href="#cb11-32" tabindex="-1"></a> }</span>
<span id="cb11-33"><a href="#cb11-33" tabindex="-1"></a>)</span></code></pre></div>
<p>We also need to define the aesthetics of the dashboard:</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" tabindex="-1"></a><span class="co">#3 Front-end layout</span></span>
<span id="cb12-2"><a href="#cb12-2" tabindex="-1"></a>layout_elements <span class="ot"><-</span> <span class="fu">list</span>(</span>
<span id="cb12-3"><a href="#cb12-3" tabindex="-1"></a> <span class="fu">h1</span>(<span class="st">"IDS Workshop - Plotly-Dash test"</span>),</span>
<span id="cb12-4"><a href="#cb12-4" tabindex="-1"></a> <span class="fu">div</span>(<span class="st">"Using the Berlin Public Toilets dataset to test Scatter Map functionality..."</span>),</span>
<span id="cb12-5"><a href="#cb12-5" tabindex="-1"></a> <span class="fu">br</span>(),</span>
<span id="cb12-6"><a href="#cb12-6" tabindex="-1"></a> <span class="fu">div</span>(<span class="st">"Type:"</span>),</span>
<span id="cb12-7"><a href="#cb12-7" tabindex="-1"></a> price_filter,</span>
<span id="cb12-8"><a href="#cb12-8" tabindex="-1"></a> <span class="fu">br</span>(),</span>
<span id="cb12-9"><a href="#cb12-9" tabindex="-1"></a> <span class="fu">div</span>(<span class="st">"Accessibility:"</span>),</span>
<span id="cb12-10"><a href="#cb12-10" tabindex="-1"></a> handicap_filter,</span>
<span id="cb12-11"><a href="#cb12-11" tabindex="-1"></a> <span class="fu">br</span>(),</span>
<span id="cb12-12"><a href="#cb12-12" tabindex="-1"></a> <span class="fu">div</span>(<span class="st">"Baby facilities:"</span>),</span>
<span id="cb12-13"><a href="#cb12-13" tabindex="-1"></a> baby_filter,</span>
<span id="cb12-14"><a href="#cb12-14" tabindex="-1"></a> <span class="fu">br</span>(),</span>
<span id="cb12-15"><a href="#cb12-15" tabindex="-1"></a> toilets_map</span>
<span id="cb12-16"><a href="#cb12-16" tabindex="-1"></a>)</span></code></pre></div>
<p>Finally, we run the app:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" tabindex="-1"></a><span class="co">#4 Main app</span></span>
<span id="cb13-2"><a href="#cb13-2" tabindex="-1"></a>app <span class="sc">|></span> <span class="fu">set_layout</span>(layout_elements)</span>
<span id="cb13-3"><a href="#cb13-3" tabindex="-1"></a>app <span class="sc">|></span> <span class="fu">run_app</span>()</span></code></pre></div>
<p>We can also add additional filters to the data, as and when
required.</p>
<p><strong>Q.5.</strong> Find the distribution of paid public toilets in
Berlin, that are also handicapped accessible and have a changing
table.</p>
<p><strong>Q.6.</strong> You have just submitted the materials for the
IDS workshop on Monday and it is officially the end of the mid-term exam
week. You go out with your friends to grab a few beers. And the weather
is really cold. Are there any free toilets in Mitte that you could use
after a grabbing some drinks with your friends?</p>
</div>
</div>
<div id="thank-you" class="section level1">
<h1>Thank you!</h1>
<p><br></p>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open');
});
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
// temporarily add toc-ignore selector to headers for the consistency with Pandoc
$('.unlisted.unnumbered').addClass('toc-ignore')
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = true;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>