-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.html
1819 lines (1811 loc) · 171 KB
/
ui.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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-99.9.9">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>ui</title>
<style>
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;}
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
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script src="ui_files/libs/clipboard/clipboard.min.js"></script>
<script src="ui_files/libs/quarto-html/quarto.js"></script>
<script src="ui_files/libs/quarto-html/popper.min.js"></script>
<script src="ui_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="ui_files/libs/quarto-html/anchor.min.js"></script>
<link href="ui_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link id="quarto-text-highlighting-styles" href="ui_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet">
<script src="ui_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="ui_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="ui_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet">
<script src="ui_files/libs/jquery-3.6.0/jquery.min.js"></script>
<script src="ui_files/libs/htmlwidgets-1.5.4/htmlwidgets.js"></script>
<link href="ui_files/libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet">
<script src="ui_files/libs/datatables-binding-0.19/datatables.js"></script>
<link href="ui_files/libs/crosstalk-1.1.1/css/crosstalk.css" rel="stylesheet">
<script src="ui_files/libs/crosstalk-1.1.1/js/crosstalk.min.js"></script>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<section id="customizing-ui" class="level1">
<h1>Customizing UI</h1>
<section id="understanding-how-to-build-a-user-interface" class="level3">
<h3 class="anchored" data-anchor-id="understanding-how-to-build-a-user-interface">Understanding how to build a user interface</h3>
</section>
<section id="interface-builder-functions" class="level2">
<h2 class="anchored" data-anchor-id="interface-builder-functions">4.1 Interface builder functions</h2>
<section id="section" class="level3">
<h3 class="anchored" data-anchor-id="section"></h3>
<p>Earlier in the course we mentioned that the UI is ultimately built with HTML. We actually use R functions to make the UI, but they get translated to HTML.</p>
<p>In this module we build on this idea to develop more complex app interfaces. More specifically, we discuss <strong>tags</strong>.</p>
</section>
<section id="tags" class="level3">
<h3 class="anchored" data-anchor-id="tags">tags</h3>
<p>Shiny comes with a list of functions saved under tags that allow us to access HTML tags and use them to add static (as opposed to reactive) content to our apps.</p>
<p>The <code>tags</code> object in shiny is a list of 100+ simple functions for constructing HTML documents. Each of the elements in this list is a function that maps to an HTML tag.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb1"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(tags)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output-stdout">
<pre><code> [1] "a" "abbr" "address"
[4] "animate" "animateMotion" "animateTransform"
[7] "area" "article" "aside"
[10] "audio" "b" "base"
[13] "bdi" "bdo" "blockquote"
[16] "body" "br" "button"
[19] "canvas" "caption" "circle"
[22] "cite" "clipPath" "code"
[25] "col" "colgroup" "color-profile"
[28] "command" "data" "datalist"
[31] "dd" "defs" "del"
[34] "desc" "details" "dfn"
[37] "dialog" "discard" "div"
[40] "dl" "dt" "ellipse"
[43] "em" "embed" "eventsource"
[46] "feBlend" "feColorMatrix" "feComponentTransfer"
[49] "feComposite" "feConvolveMatrix" "feDiffuseLighting"
[52] "feDisplacementMap" "feDistantLight" "feDropShadow"
[55] "feFlood" "feFuncA" "feFuncB"
[58] "feFuncG" "feFuncR" "feGaussianBlur"
[61] "feImage" "feMerge" "feMergeNode"
[64] "feMorphology" "feOffset" "fePointLight"
[67] "feSpecularLighting" "feSpotLight" "feTile"
[70] "feTurbulence" "fieldset" "figcaption"
[73] "figure" "filter" "footer"
[76] "foreignObject" "form" "g"
[79] "h1" "h2" "h3"
[82] "h4" "h5" "h6"
[85] "hatch" "hatchpath" "head"
[88] "header" "hgroup" "hr"
[91] "html" "i" "iframe"
[94] "image" "img" "input"
[97] "ins" "kbd" "keygen"
[100] "label" "legend" "li"
[103] "line" "linearGradient" "link"
[106] "main" "map" "mark"
[109] "marker" "mask" "menu"
[112] "meta" "metadata" "meter"
[115] "mpath" "nav" "noscript"
[118] "object" "ol" "optgroup"
[121] "option" "output" "p"
[124] "param" "path" "pattern"
[127] "picture" "polygon" "polyline"
[130] "pre" "progress" "q"
[133] "radialGradient" "rb" "rect"
[136] "rp" "rt" "rtc"
[139] "ruby" "s" "samp"
[142] "script" "section" "select"
[145] "set" "slot" "small"
[148] "solidcolor" "source" "span"
[151] "stop" "strong" "style"
[154] "sub" "summary" "sup"
[157] "svg" "switch" "symbol"
[160] "table" "tbody" "td"
[163] "template" "text" "textarea"
[166] "textPath" "tfoot" "th"
[169] "thead" "time" "title"
[172] "tr" "track" "tspan"
[175] "u" "ul" "use"
[178] "var" "video" "view"
[181] "wbr" </code></pre>
</div>
</div>
</section>
<section id="tag---html" class="level3">
<h3 class="anchored" data-anchor-id="tag---html">tag -> HTML</h3>
<p>For example, let’s use the <code>b</code> tag, which is used for bolding text in HTML. The function is <code>tags$b()</code>.</p>
<p>You can pass a text string, in quotation marks, to this function, like “This is my first app”.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb3"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">b</span>(<span class="st">"This is my first app"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Then R translates the text string to HTML:</p>
<pre><code><b>This is my first app</b> </code></pre>
<p>The HTML is then rendered as bolded text when the user sees it:</p>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<p><b>This is my first app</b></p>
</div>
</div>
</section>
<section id="header-tags" class="level3">
<h3 class="anchored">Header tags</h3>
<p>So how would you use these tags in building an app?</p>
<p>You might use the various levels of headers if it makes sense for to have subheadings in my app.</p>
<p>For example <code>tags$h1()</code>, <code>tags$h2()</code>, and <code>tags$h3()</code> to create first, second, and third level headings, etc.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb5"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with tags</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">h1</span>(<span class="st">"First level heading"</span>), </span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">h2</span>(<span class="st">"Second level heading"</span>), </span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">h3</span>(<span class="st">"Third level heading"</span>)</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server function that does nothing :)</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the app object</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<h1>First level heading</h1>
<h2 class="anchored" data-anchor-id="header-tags">Second level heading</h2>
<h3 class="anchored">Third level heading</h3>
</div>
</div>
</div>
<hr>
</section>
<section id="linked-text" class="level3">
<h3 class="anchored" data-anchor-id="linked-text">Linked text</h3>
<p>If you have references you want to link to at the bottom of you app, you can use the a tag with the <code>href</code> argument for specifying a URL.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb6"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with tags</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>( </span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">h1</span>(<span class="st">"Awesome title"</span>), </span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">br</span>(), <span class="co"># line break </span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">a</span>(<span class="st">"This app is built with Shiny."</span>, <span class="at">href =</span> <span class="st">"http://shiny.rstudio.com/"</span>)</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server fn that does nothing :)</span></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the app object</span></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<h1>Awesome title</h1>
<br>
<a href="http://shiny.rstudio.com/">This app is built with Shiny.</a>
</div>
</div>
</div>
<hr>
</section>
<section id="nested-tags" class="level3">
<h3 class="anchored" data-anchor-id="nested-tags">Nested tags</h3>
<p>You can also nest tags within each other to create something like a new paragraph with the <code>p</code> tag and some text in that paragraph where certain words are italicized with the <code>em</code> tag and certain are bolded with the <code>b</code> tag.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb7"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with tags</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>( </span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">p</span>(</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"Lorem ipsum"</span>,</span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">em</span>(<span class="st">"dolor"</span>),</span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a> <span class="st">"sit amet,"</span>,</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">b</span>(<span class="st">"consectetur"</span>),</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a> <span class="st">"adipiscing elit."</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server fn that does nothing :)</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the app object</span></span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<p>
Lorem ipsum
<em>dolor</em>
sit amet,
<b>consectetur</b>
adipiscing elit.
</p>
</div>
</div>
</div>
<hr>
</section>
<section id="common-tags" class="level3">
<h3 class="anchored" data-anchor-id="common-tags">Common tags</h3>
<p>Additionally, the most commonly used tags are wrapped in their own functions and you can use them without the tags list.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb8"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">p</span>(...) <span class="ot">-></span> <span class="fu">p</span>(...)</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">h1</span>(...) <span class="ot">-></span> <span class="fu">h1</span>(...)</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">h2</span>(...) <span class="ot">-></span> <span class="fu">h2</span>(...)</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">h3</span>(...) <span class="ot">-></span> <span class="fu">h3</span>(...)</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">h4</span>(...) <span class="ot">-></span> <span class="fu">h4</span>(...)</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">h5</span>(...) <span class="ot">-></span> <span class="fu">h5</span>(...)</span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">h6</span>(...) <span class="ot">-></span> <span class="fu">h6</span>(...)</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">a</span>(...) <span class="ot">-></span> <span class="fu">a</span>(...)</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">br</span>(...) <span class="ot">-></span> <span class="fu">br</span>(...)</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">div</span>(...) <span class="ot">-></span> <span class="fu">div</span>(...)</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">span</span>(...) <span class="ot">-></span> <span class="fu">span</span>(...)</span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">pre</span>(...) <span class="ot">-></span> <span class="fu">pre</span>(...)</span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">code</span>(...) <span class="ot">-></span> <span class="fu">code</span>(...)</span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">img</span>(...) <span class="ot">-></span> <span class="fu">img</span>(...)</span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">strong</span>(...) <span class="ot">-></span> <span class="fu">strong</span>(...)</span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">em</span>(...) <span class="ot">-></span> <span class="fu">em</span>(...)</span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">hr</span>(...) <span class="ot">-></span> <span class="fu">hr</span>(...)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="section-1" class="level3">
<h3 class="anchored" data-anchor-id="section-1"></h3>
<p>These are functions like:</p>
<ul>
<li><p><code>a()</code> for anchor text.</p>
<p>::: {.cell layout-align=“center”}</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">a</span>(<span class="st">"Anchor text"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>::: <code><a>Anchor text</a></code> ::: {.cell layout-align=“center”}</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">a</span>(<span class="st">"Anchor text"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>::: <code><a>Anchor text</a></code></p></li>
<li><p><code>br()</code> for a line break.</p>
<p>::: {.cell layout-align=“center”}</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">br</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>::: <code><br></code></p>
<p>::: {.cell layout-align=“center”}</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">br</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>::: <code><br></code></p></li>
<li><p><code>code()</code> for displaying code in monospace form<br>
::: {.cell layout-align=“center”}</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">code</span>(<span class="st">"Monospace text"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>:::</p>
<pre><code><code>Monospace text</code></code></pre>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb15"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">code</span>(<span class="st">"Monospace text"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<pre><code><code>Monospace text</code></code></pre></li>
<li><p>And the heading functions we mentioned earlier<br>
::: {.cell layout-align=“center”}</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>tags<span class="sc">$</span><span class="fu">h1</span>(<span class="st">"First level header"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>::: <code><h1>First level header</h1></code></p>
<p>::: {.cell layout-align=“center”}</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="fu">h1</span>(<span class="st">"First level header"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>::: <code><h1>First level header</h1></code></p></li>
</ul>
<p>The function names correspond to the tag names, and the functions accept text strings as arguments. For example <code>tags$h1("First level heading")</code> is equivalent to <code>h1("First level heading")</code>.</p>
</section>
<section id="html" class="level3">
<h3 class="anchored" data-anchor-id="html">HTML</h3>
<p>If you’re comfortable with HTML, an alternative is to directly use HTML syntax and wrap your HTML code with the HTML function.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb19"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">HTML</span>(<span class="st">"Hello world, <br/> and then a line break."</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<pre><code>Hello world, <br/> and then a line break.</code></pre>
</section>
<section id="practice" class="level3">
<h3 class="anchored" data-anchor-id="practice">Practice</h3>
<p>Next, let’s work on some exercises on adding HTML elements to our apps to customize appearance.</p>
<p>These next exercises will demo a few of the simpler interface builder options with HTML code.</p>
</section>
<section id="practice---add-text-with-html-tags" class="level3">
<h3 class="anchored" data-anchor-id="practice---add-text-with-html-tags">Practice - Add text with HTML tags</h3>
<section id="your-turn" class="level4">
<h4 class="anchored" data-anchor-id="your-turn">Your turn</h4>
<p>Add explanatory text to your movie app by using HTML tags in the main panel.</p>
<p>Below is some sample text you can add. Note that you should replace <code>[NUMBER OF MOVIES]</code> with with the number of movies in the sample, and instead of hardcoding this value, you can use <code>nrow(movies)</code> to calculate it.</p>
<pre><code>These data were obtained from <a href="http://www.imbd.com/">IMBD</a> and
<a href="https://www.rottentomatoes.com/">Rotten Tomatoes</a>.
The data represent _[NUMBER OF MOVIES]_ randomly sampled movies released between 1972 to 2014 in the United States.</code></pre>
<div class="proj">
<p><em>Navigate to the RStudio Cloud Project titled <strong>4-1a Add text with HTML tags</strong> in your RStudio Workspace to see this code in action</em></p>
<p><a href="https://rstudio.cloud/spaces/81721/join?access_code=I4VJaNsKfTqR3Td9hLP7E1nz8%2FtMg6Xbw9Bgqumv" class="btn test-drive"><i class="fa fa-cloud"></i> Go to RStudio Cloud Project</a></p>
</div>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb22"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Load packages ----------------------------------------------------------------</span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tools)</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Load data --------------------------------------------------------------------</span></span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a><span class="fu">load</span>(<span class="st">"movies.RData"</span>)</span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI --------------------------------------------------------------------</span></span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarLayout</span>(</span>
<span id="cb22-15"><a href="#cb22-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarPanel</span>(</span>
<span id="cb22-16"><a href="#cb22-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">selectInput</span>(</span>
<span id="cb22-17"><a href="#cb22-17" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"y"</span>,</span>
<span id="cb22-18"><a href="#cb22-18" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Y-axis:"</span>,</span>
<span id="cb22-19"><a href="#cb22-19" aria-hidden="true" tabindex="-1"></a> <span class="at">choices =</span> <span class="fu">c</span>(</span>
<span id="cb22-20"><a href="#cb22-20" aria-hidden="true" tabindex="-1"></a> <span class="st">"IMDB rating"</span> <span class="ot">=</span> <span class="st">"imdb_rating"</span>,</span>
<span id="cb22-21"><a href="#cb22-21" aria-hidden="true" tabindex="-1"></a> <span class="st">"IMDB number of votes"</span> <span class="ot">=</span> <span class="st">"imdb_num_votes"</span>,</span>
<span id="cb22-22"><a href="#cb22-22" aria-hidden="true" tabindex="-1"></a> <span class="st">"Critics Score"</span> <span class="ot">=</span> <span class="st">"critics_score"</span>,</span>
<span id="cb22-23"><a href="#cb22-23" aria-hidden="true" tabindex="-1"></a> <span class="st">"Audience Score"</span> <span class="ot">=</span> <span class="st">"audience_score"</span>,</span>
<span id="cb22-24"><a href="#cb22-24" aria-hidden="true" tabindex="-1"></a> <span class="st">"Runtime"</span> <span class="ot">=</span> <span class="st">"runtime"</span></span>
<span id="cb22-25"><a href="#cb22-25" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-26"><a href="#cb22-26" aria-hidden="true" tabindex="-1"></a> <span class="at">selected =</span> <span class="st">"audience_score"</span></span>
<span id="cb22-27"><a href="#cb22-27" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-28"><a href="#cb22-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-29"><a href="#cb22-29" aria-hidden="true" tabindex="-1"></a> <span class="fu">selectInput</span>(</span>
<span id="cb22-30"><a href="#cb22-30" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"x"</span>,</span>
<span id="cb22-31"><a href="#cb22-31" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"X-axis:"</span>,</span>
<span id="cb22-32"><a href="#cb22-32" aria-hidden="true" tabindex="-1"></a> <span class="at">choices =</span> <span class="fu">c</span>(</span>
<span id="cb22-33"><a href="#cb22-33" aria-hidden="true" tabindex="-1"></a> <span class="st">"IMDB rating"</span> <span class="ot">=</span> <span class="st">"imdb_rating"</span>,</span>
<span id="cb22-34"><a href="#cb22-34" aria-hidden="true" tabindex="-1"></a> <span class="st">"IMDB number of votes"</span> <span class="ot">=</span> <span class="st">"imdb_num_votes"</span>,</span>
<span id="cb22-35"><a href="#cb22-35" aria-hidden="true" tabindex="-1"></a> <span class="st">"Critics Score"</span> <span class="ot">=</span> <span class="st">"critics_score"</span>,</span>
<span id="cb22-36"><a href="#cb22-36" aria-hidden="true" tabindex="-1"></a> <span class="st">"Audience Score"</span> <span class="ot">=</span> <span class="st">"audience_score"</span>,</span>
<span id="cb22-37"><a href="#cb22-37" aria-hidden="true" tabindex="-1"></a> <span class="st">"Runtime"</span> <span class="ot">=</span> <span class="st">"runtime"</span></span>
<span id="cb22-38"><a href="#cb22-38" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-39"><a href="#cb22-39" aria-hidden="true" tabindex="-1"></a> <span class="at">selected =</span> <span class="st">"critics_score"</span></span>
<span id="cb22-40"><a href="#cb22-40" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-41"><a href="#cb22-41" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-42"><a href="#cb22-42" aria-hidden="true" tabindex="-1"></a> <span class="fu">selectInput</span>(</span>
<span id="cb22-43"><a href="#cb22-43" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"z"</span>,</span>
<span id="cb22-44"><a href="#cb22-44" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Color by:"</span>,</span>
<span id="cb22-45"><a href="#cb22-45" aria-hidden="true" tabindex="-1"></a> <span class="at">choices =</span> <span class="fu">c</span>(</span>
<span id="cb22-46"><a href="#cb22-46" aria-hidden="true" tabindex="-1"></a> <span class="st">"Title Type"</span> <span class="ot">=</span> <span class="st">"title_type"</span>,</span>
<span id="cb22-47"><a href="#cb22-47" aria-hidden="true" tabindex="-1"></a> <span class="st">"Genre"</span> <span class="ot">=</span> <span class="st">"genre"</span>,</span>
<span id="cb22-48"><a href="#cb22-48" aria-hidden="true" tabindex="-1"></a> <span class="st">"MPAA Rating"</span> <span class="ot">=</span> <span class="st">"mpaa_rating"</span>,</span>
<span id="cb22-49"><a href="#cb22-49" aria-hidden="true" tabindex="-1"></a> <span class="st">"Critics Rating"</span> <span class="ot">=</span> <span class="st">"critics_rating"</span>,</span>
<span id="cb22-50"><a href="#cb22-50" aria-hidden="true" tabindex="-1"></a> <span class="st">"Audience Rating"</span> <span class="ot">=</span> <span class="st">"audience_rating"</span></span>
<span id="cb22-51"><a href="#cb22-51" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-52"><a href="#cb22-52" aria-hidden="true" tabindex="-1"></a> <span class="at">selected =</span> <span class="st">"mpaa_rating"</span></span>
<span id="cb22-53"><a href="#cb22-53" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-54"><a href="#cb22-54" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-55"><a href="#cb22-55" aria-hidden="true" tabindex="-1"></a> <span class="fu">sliderInput</span>(</span>
<span id="cb22-56"><a href="#cb22-56" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"alpha"</span>,</span>
<span id="cb22-57"><a href="#cb22-57" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Alpha:"</span>,</span>
<span id="cb22-58"><a href="#cb22-58" aria-hidden="true" tabindex="-1"></a> <span class="at">min =</span> <span class="dv">0</span>, <span class="at">max =</span> <span class="dv">1</span>,</span>
<span id="cb22-59"><a href="#cb22-59" aria-hidden="true" tabindex="-1"></a> <span class="at">value =</span> <span class="fl">0.5</span></span>
<span id="cb22-60"><a href="#cb22-60" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-61"><a href="#cb22-61" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-62"><a href="#cb22-62" aria-hidden="true" tabindex="-1"></a> <span class="fu">sliderInput</span>(</span>
<span id="cb22-63"><a href="#cb22-63" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"size"</span>,</span>
<span id="cb22-64"><a href="#cb22-64" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Size:"</span>,</span>
<span id="cb22-65"><a href="#cb22-65" aria-hidden="true" tabindex="-1"></a> <span class="at">min =</span> <span class="dv">0</span>, <span class="at">max =</span> <span class="dv">5</span>,</span>
<span id="cb22-66"><a href="#cb22-66" aria-hidden="true" tabindex="-1"></a> <span class="at">value =</span> <span class="dv">2</span></span>
<span id="cb22-67"><a href="#cb22-67" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-68"><a href="#cb22-68" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-69"><a href="#cb22-69" aria-hidden="true" tabindex="-1"></a> <span class="fu">textInput</span>(</span>
<span id="cb22-70"><a href="#cb22-70" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"plot_title"</span>,</span>
<span id="cb22-71"><a href="#cb22-71" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Plot title"</span>,</span>
<span id="cb22-72"><a href="#cb22-72" aria-hidden="true" tabindex="-1"></a> <span class="at">placeholder =</span> <span class="st">"Enter text to be used as plot title"</span></span>
<span id="cb22-73"><a href="#cb22-73" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-74"><a href="#cb22-74" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-75"><a href="#cb22-75" aria-hidden="true" tabindex="-1"></a> <span class="fu">actionButton</span>(</span>
<span id="cb22-76"><a href="#cb22-76" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"update_plot_title"</span>,</span>
<span id="cb22-77"><a href="#cb22-77" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Update plot title"</span></span>
<span id="cb22-78"><a href="#cb22-78" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb22-79"><a href="#cb22-79" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb22-80"><a href="#cb22-80" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-81"><a href="#cb22-81" aria-hidden="true" tabindex="-1"></a> <span class="fu">mainPanel</span>(</span>
<span id="cb22-82"><a href="#cb22-82" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">br</span>(),</span>
<span id="cb22-83"><a href="#cb22-83" aria-hidden="true" tabindex="-1"></a> ___, <span class="co"># add text here</span></span>
<span id="cb22-84"><a href="#cb22-84" aria-hidden="true" tabindex="-1"></a> <span class="fu">plotOutput</span>(<span class="at">outputId =</span> <span class="st">"scatterplot"</span>)</span>
<span id="cb22-85"><a href="#cb22-85" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb22-86"><a href="#cb22-86" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb22-87"><a href="#cb22-87" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb22-88"><a href="#cb22-88" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-89"><a href="#cb22-89" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server ----------------------------------------------------------------</span></span>
<span id="cb22-90"><a href="#cb22-90" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-91"><a href="#cb22-91" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {</span>
<span id="cb22-92"><a href="#cb22-92" aria-hidden="true" tabindex="-1"></a> new_plot_title <span class="ot"><-</span> <span class="fu">eventReactive</span>(</span>
<span id="cb22-93"><a href="#cb22-93" aria-hidden="true" tabindex="-1"></a> <span class="at">eventExpr =</span> input<span class="sc">$</span>update_plot_title,</span>
<span id="cb22-94"><a href="#cb22-94" aria-hidden="true" tabindex="-1"></a> <span class="at">valueExpr =</span> {</span>
<span id="cb22-95"><a href="#cb22-95" aria-hidden="true" tabindex="-1"></a> <span class="fu">toTitleCase</span>(input<span class="sc">$</span>plot_title)</span>
<span id="cb22-96"><a href="#cb22-96" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb22-97"><a href="#cb22-97" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb22-98"><a href="#cb22-98" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-99"><a href="#cb22-99" aria-hidden="true" tabindex="-1"></a> output<span class="sc">$</span>scatterplot <span class="ot"><-</span> <span class="fu">renderPlot</span>({</span>
<span id="cb22-100"><a href="#cb22-100" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="at">data =</span> movies, <span class="fu">aes_string</span>(<span class="at">x =</span> input<span class="sc">$</span>x, <span class="at">y =</span> input<span class="sc">$</span>y, <span class="at">color =</span> input<span class="sc">$</span>z)) <span class="sc">+</span></span>
<span id="cb22-101"><a href="#cb22-101" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">alpha =</span> input<span class="sc">$</span>alpha, <span class="at">size =</span> input<span class="sc">$</span>size) <span class="sc">+</span></span>
<span id="cb22-102"><a href="#cb22-102" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="fu">new_plot_title</span>())</span>
<span id="cb22-103"><a href="#cb22-103" aria-hidden="true" tabindex="-1"></a> })</span>
<span id="cb22-104"><a href="#cb22-104" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb22-105"><a href="#cb22-105" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-106"><a href="#cb22-106" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the Shiny app object --------------------------------------------------</span></span>
<span id="cb22-107"><a href="#cb22-107" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-108"><a href="#cb22-108" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<details>
<summary>
Show solution
</summary>
<p>See the following code chunk for the solution to the exercise above.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb23"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Load packages ----------------------------------------------------------------</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tools)</span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Load data --------------------------------------------------------------------</span></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a><span class="fu">load</span>(<span class="st">"movies.RData"</span>)</span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-11"><a href="#cb23-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI --------------------------------------------------------------------</span></span>
<span id="cb23-12"><a href="#cb23-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-13"><a href="#cb23-13" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb23-14"><a href="#cb23-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarLayout</span>(</span>
<span id="cb23-15"><a href="#cb23-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarPanel</span>(</span>
<span id="cb23-16"><a href="#cb23-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">selectInput</span>(</span>
<span id="cb23-17"><a href="#cb23-17" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"y"</span>,</span>
<span id="cb23-18"><a href="#cb23-18" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Y-axis:"</span>,</span>
<span id="cb23-19"><a href="#cb23-19" aria-hidden="true" tabindex="-1"></a> <span class="at">choices =</span> <span class="fu">c</span>(</span>
<span id="cb23-20"><a href="#cb23-20" aria-hidden="true" tabindex="-1"></a> <span class="st">"IMDB rating"</span> <span class="ot">=</span> <span class="st">"imdb_rating"</span>,</span>
<span id="cb23-21"><a href="#cb23-21" aria-hidden="true" tabindex="-1"></a> <span class="st">"IMDB number of votes"</span> <span class="ot">=</span> <span class="st">"imdb_num_votes"</span>,</span>
<span id="cb23-22"><a href="#cb23-22" aria-hidden="true" tabindex="-1"></a> <span class="st">"Critics Score"</span> <span class="ot">=</span> <span class="st">"critics_score"</span>,</span>
<span id="cb23-23"><a href="#cb23-23" aria-hidden="true" tabindex="-1"></a> <span class="st">"Audience Score"</span> <span class="ot">=</span> <span class="st">"audience_score"</span>,</span>
<span id="cb23-24"><a href="#cb23-24" aria-hidden="true" tabindex="-1"></a> <span class="st">"Runtime"</span> <span class="ot">=</span> <span class="st">"runtime"</span></span>
<span id="cb23-25"><a href="#cb23-25" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-26"><a href="#cb23-26" aria-hidden="true" tabindex="-1"></a> <span class="at">selected =</span> <span class="st">"audience_score"</span></span>
<span id="cb23-27"><a href="#cb23-27" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-28"><a href="#cb23-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-29"><a href="#cb23-29" aria-hidden="true" tabindex="-1"></a> <span class="fu">selectInput</span>(</span>
<span id="cb23-30"><a href="#cb23-30" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"x"</span>,</span>
<span id="cb23-31"><a href="#cb23-31" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"X-axis:"</span>,</span>
<span id="cb23-32"><a href="#cb23-32" aria-hidden="true" tabindex="-1"></a> <span class="at">choices =</span> <span class="fu">c</span>(</span>
<span id="cb23-33"><a href="#cb23-33" aria-hidden="true" tabindex="-1"></a> <span class="st">"IMDB rating"</span> <span class="ot">=</span> <span class="st">"imdb_rating"</span>,</span>
<span id="cb23-34"><a href="#cb23-34" aria-hidden="true" tabindex="-1"></a> <span class="st">"IMDB number of votes"</span> <span class="ot">=</span> <span class="st">"imdb_num_votes"</span>,</span>
<span id="cb23-35"><a href="#cb23-35" aria-hidden="true" tabindex="-1"></a> <span class="st">"Critics Score"</span> <span class="ot">=</span> <span class="st">"critics_score"</span>,</span>
<span id="cb23-36"><a href="#cb23-36" aria-hidden="true" tabindex="-1"></a> <span class="st">"Audience Score"</span> <span class="ot">=</span> <span class="st">"audience_score"</span>,</span>
<span id="cb23-37"><a href="#cb23-37" aria-hidden="true" tabindex="-1"></a> <span class="st">"Runtime"</span> <span class="ot">=</span> <span class="st">"runtime"</span></span>
<span id="cb23-38"><a href="#cb23-38" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-39"><a href="#cb23-39" aria-hidden="true" tabindex="-1"></a> <span class="at">selected =</span> <span class="st">"critics_score"</span></span>
<span id="cb23-40"><a href="#cb23-40" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-41"><a href="#cb23-41" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-42"><a href="#cb23-42" aria-hidden="true" tabindex="-1"></a> <span class="fu">selectInput</span>(</span>
<span id="cb23-43"><a href="#cb23-43" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"z"</span>,</span>
<span id="cb23-44"><a href="#cb23-44" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Color by:"</span>,</span>
<span id="cb23-45"><a href="#cb23-45" aria-hidden="true" tabindex="-1"></a> <span class="at">choices =</span> <span class="fu">c</span>(</span>
<span id="cb23-46"><a href="#cb23-46" aria-hidden="true" tabindex="-1"></a> <span class="st">"Title Type"</span> <span class="ot">=</span> <span class="st">"title_type"</span>,</span>
<span id="cb23-47"><a href="#cb23-47" aria-hidden="true" tabindex="-1"></a> <span class="st">"Genre"</span> <span class="ot">=</span> <span class="st">"genre"</span>,</span>
<span id="cb23-48"><a href="#cb23-48" aria-hidden="true" tabindex="-1"></a> <span class="st">"MPAA Rating"</span> <span class="ot">=</span> <span class="st">"mpaa_rating"</span>,</span>
<span id="cb23-49"><a href="#cb23-49" aria-hidden="true" tabindex="-1"></a> <span class="st">"Critics Rating"</span> <span class="ot">=</span> <span class="st">"critics_rating"</span>,</span>
<span id="cb23-50"><a href="#cb23-50" aria-hidden="true" tabindex="-1"></a> <span class="st">"Audience Rating"</span> <span class="ot">=</span> <span class="st">"audience_rating"</span></span>
<span id="cb23-51"><a href="#cb23-51" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-52"><a href="#cb23-52" aria-hidden="true" tabindex="-1"></a> <span class="at">selected =</span> <span class="st">"mpaa_rating"</span></span>
<span id="cb23-53"><a href="#cb23-53" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-54"><a href="#cb23-54" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-55"><a href="#cb23-55" aria-hidden="true" tabindex="-1"></a> <span class="fu">sliderInput</span>(</span>
<span id="cb23-56"><a href="#cb23-56" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"alpha"</span>,</span>
<span id="cb23-57"><a href="#cb23-57" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Alpha:"</span>,</span>
<span id="cb23-58"><a href="#cb23-58" aria-hidden="true" tabindex="-1"></a> <span class="at">min =</span> <span class="dv">0</span>, <span class="at">max =</span> <span class="dv">1</span>,</span>
<span id="cb23-59"><a href="#cb23-59" aria-hidden="true" tabindex="-1"></a> <span class="at">value =</span> <span class="fl">0.5</span></span>
<span id="cb23-60"><a href="#cb23-60" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-61"><a href="#cb23-61" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-62"><a href="#cb23-62" aria-hidden="true" tabindex="-1"></a> <span class="fu">sliderInput</span>(</span>
<span id="cb23-63"><a href="#cb23-63" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"size"</span>,</span>
<span id="cb23-64"><a href="#cb23-64" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Size:"</span>,</span>
<span id="cb23-65"><a href="#cb23-65" aria-hidden="true" tabindex="-1"></a> <span class="at">min =</span> <span class="dv">0</span>, <span class="at">max =</span> <span class="dv">5</span>,</span>
<span id="cb23-66"><a href="#cb23-66" aria-hidden="true" tabindex="-1"></a> <span class="at">value =</span> <span class="dv">2</span></span>
<span id="cb23-67"><a href="#cb23-67" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-68"><a href="#cb23-68" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-69"><a href="#cb23-69" aria-hidden="true" tabindex="-1"></a> <span class="fu">textInput</span>(</span>
<span id="cb23-70"><a href="#cb23-70" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"plot_title"</span>,</span>
<span id="cb23-71"><a href="#cb23-71" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Plot title"</span>,</span>
<span id="cb23-72"><a href="#cb23-72" aria-hidden="true" tabindex="-1"></a> <span class="at">placeholder =</span> <span class="st">"Enter text to be used as plot title"</span></span>
<span id="cb23-73"><a href="#cb23-73" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-74"><a href="#cb23-74" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-75"><a href="#cb23-75" aria-hidden="true" tabindex="-1"></a> <span class="fu">actionButton</span>(</span>
<span id="cb23-76"><a href="#cb23-76" aria-hidden="true" tabindex="-1"></a> <span class="at">inputId =</span> <span class="st">"update_plot_title"</span>,</span>
<span id="cb23-77"><a href="#cb23-77" aria-hidden="true" tabindex="-1"></a> <span class="at">label =</span> <span class="st">"Update plot title"</span></span>
<span id="cb23-78"><a href="#cb23-78" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb23-79"><a href="#cb23-79" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-80"><a href="#cb23-80" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-81"><a href="#cb23-81" aria-hidden="true" tabindex="-1"></a> <span class="fu">mainPanel</span>(</span>
<span id="cb23-82"><a href="#cb23-82" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">br</span>(),</span>
<span id="cb23-83"><a href="#cb23-83" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">p</span>(</span>
<span id="cb23-84"><a href="#cb23-84" aria-hidden="true" tabindex="-1"></a> <span class="st">"These data were obtained from"</span>,</span>
<span id="cb23-85"><a href="#cb23-85" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">a</span>(<span class="st">"IMBD"</span>, <span class="at">href =</span> <span class="st">"http://www.imbd.com/"</span>), <span class="st">"and"</span>,</span>
<span id="cb23-86"><a href="#cb23-86" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">a</span>(<span class="st">"Rotten Tomatoes"</span>, <span class="at">href =</span> <span class="st">"https://www.rottentomatoes.com/"</span>), <span class="st">"."</span></span>
<span id="cb23-87"><a href="#cb23-87" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb23-88"><a href="#cb23-88" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">p</span>(<span class="st">"The data represent"</span>, <span class="fu">nrow</span>(movies), <span class="st">"randomly sampled movies released between 1972 to 2014 in the United States."</span>),</span>
<span id="cb23-89"><a href="#cb23-89" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-90"><a href="#cb23-90" aria-hidden="true" tabindex="-1"></a> <span class="fu">plotOutput</span>(<span class="at">outputId =</span> <span class="st">"scatterplot"</span>)</span>
<span id="cb23-91"><a href="#cb23-91" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb23-92"><a href="#cb23-92" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb23-93"><a href="#cb23-93" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb23-94"><a href="#cb23-94" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-95"><a href="#cb23-95" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server ----------------------------------------------------------------</span></span>
<span id="cb23-96"><a href="#cb23-96" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-97"><a href="#cb23-97" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {</span>
<span id="cb23-98"><a href="#cb23-98" aria-hidden="true" tabindex="-1"></a> new_plot_title <span class="ot"><-</span> <span class="fu">eventReactive</span>(</span>
<span id="cb23-99"><a href="#cb23-99" aria-hidden="true" tabindex="-1"></a> <span class="at">eventExpr =</span> input<span class="sc">$</span>update_plot_title,</span>
<span id="cb23-100"><a href="#cb23-100" aria-hidden="true" tabindex="-1"></a> <span class="at">valueExpr =</span> {</span>
<span id="cb23-101"><a href="#cb23-101" aria-hidden="true" tabindex="-1"></a> <span class="fu">toTitleCase</span>(input<span class="sc">$</span>plot_title)</span>
<span id="cb23-102"><a href="#cb23-102" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb23-103"><a href="#cb23-103" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb23-104"><a href="#cb23-104" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-105"><a href="#cb23-105" aria-hidden="true" tabindex="-1"></a> output<span class="sc">$</span>scatterplot <span class="ot"><-</span> <span class="fu">renderPlot</span>({</span>
<span id="cb23-106"><a href="#cb23-106" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="at">data =</span> movies, <span class="fu">aes_string</span>(<span class="at">x =</span> input<span class="sc">$</span>x, <span class="at">y =</span> input<span class="sc">$</span>y, <span class="at">color =</span> input<span class="sc">$</span>z)) <span class="sc">+</span></span>
<span id="cb23-107"><a href="#cb23-107" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>(<span class="at">alpha =</span> input<span class="sc">$</span>alpha, <span class="at">size =</span> input<span class="sc">$</span>size) <span class="sc">+</span></span>
<span id="cb23-108"><a href="#cb23-108" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="fu">new_plot_title</span>())</span>
<span id="cb23-109"><a href="#cb23-109" aria-hidden="true" tabindex="-1"></a> })</span>
<span id="cb23-110"><a href="#cb23-110" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb23-111"><a href="#cb23-111" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-112"><a href="#cb23-112" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the Shiny app object --------------------------------------------------</span></span>
<span id="cb23-113"><a href="#cb23-113" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-114"><a href="#cb23-114" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</details>
</section>
</section>
<section id="practice---add-image-with-the-img-tag" class="level3">
<h3 class="anchored" data-anchor-id="practice---add-image-with-the-img-tag">Practice - Add image with the <code>img</code> tag</h3>
<section id="your-turn-1" class="level4">
<h4 class="anchored" data-anchor-id="your-turn-1">Your turn</h4>
<p>Now let’s practice adding an image to a very simple app.</p>
<p>Note that if you’d like to use a local image for with your app, you’ll first have to save the image in a folder <code>www/</code> within your root directory. You’ll see what we mean when you run the demo in the RStudio Cloud Project. Set a height and width for your image as well.</p>
<div class="proj">
<p><em>Navigate to the RStudio Cloud Project titled <strong>4-1b Add image with img tag</strong> in your RStudio Workspace for the demo</em></p>
<p><a href="https://rstudio.cloud/spaces/81721/join?access_code=I4VJaNsKfTqR3Td9hLP7E1nz8%2FtMg6Xbw9Bgqumv" class="btn test-drive"><i class="fa fa-cloud"></i> Go to RStudio Cloud Project</a></p>
</div>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb24"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Load packages ----------------------------------------------------------------</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI --------------------------------------------------------------------</span></span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">titlePanel</span>(<span class="st">"An image"</span>),</span>
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">img</span>(___),</span>
<span id="cb24-11"><a href="#cb24-11" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb24-12"><a href="#cb24-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-13"><a href="#cb24-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server ----------------------------------------------------------------</span></span>
<span id="cb24-14"><a href="#cb24-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-15"><a href="#cb24-15" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb24-16"><a href="#cb24-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-17"><a href="#cb24-17" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the Shiny app ---------------------------------------------------------</span></span>
<span id="cb24-18"><a href="#cb24-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-19"><a href="#cb24-19" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<details>
<summary>
Show solution
</summary>
<p>See the following code chunk for the solution to the exercise above.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb25"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Load packages ----------------------------------------------------------------</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI --------------------------------------------------------------------</span></span>
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-8"><a href="#cb25-8" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb25-9"><a href="#cb25-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">titlePanel</span>(<span class="st">"An image"</span>),</span>
<span id="cb25-10"><a href="#cb25-10" aria-hidden="true" tabindex="-1"></a> tags<span class="sc">$</span><span class="fu">img</span>(<span class="at">height =</span> <span class="dv">100</span>, <span class="at">width =</span> <span class="dv">300</span>, <span class="at">src =</span> <span class="st">"roles_implement.png"</span>),</span>
<span id="cb25-11"><a href="#cb25-11" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb25-12"><a href="#cb25-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-13"><a href="#cb25-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server ----------------------------------------------------------------</span></span>
<span id="cb25-14"><a href="#cb25-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-15"><a href="#cb25-15" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb25-16"><a href="#cb25-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-17"><a href="#cb25-17" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the Shiny app ---------------------------------------------------------</span></span>
<span id="cb25-18"><a href="#cb25-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb25-19"><a href="#cb25-19" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</details>
</section>
</section>
</section>
<section id="layout-panels" class="level2">
<h2 class="anchored" data-anchor-id="layout-panels">4.2 Layout Panels</h2>
<p>In this section we discuss the layout of a Shiny app.</p>
<section id="fluidrow" class="level3">
<h3 class="anchored" data-anchor-id="fluidrow"><code>fluidRow()</code></h3>
<p>One useful function for customizing the layout of your app is <code>fluidRow()</code>. This function creates horizontal rows where objects can be placed.</p>
<p>You can add as many rows as you want, but you want to be careful about expanding your app too much vertically as your users might not be willing to scroll down to interact with your app in full.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb26"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with fluid rows</span></span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"Side"</span>, <span class="st">"by"</span>, <span class="st">"side"</span>, <span class="st">"text"</span>,</span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">fluidRow</span>(<span class="st">"Text on row 1"</span>),</span>
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">fluidRow</span>(<span class="st">"Text on row 2"</span>),</span>
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">fluidRow</span>(<span class="st">"Text on row 3"</span>)</span>
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server function that does nothing</span></span>
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb26-14"><a href="#cb26-14" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the app object</span></span>
<span id="cb26-15"><a href="#cb26-15" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
Side
by
side
text
<div class="row">Text on row 1</div>
<div class="row">Text on row 2</div>
<div class="row">Text on row 3</div>
</div>
</div>
</div>
<hr>
</section>
<section id="column" class="level3">
<h3 class="anchored" data-anchor-id="column"><code>column()</code></h3>
<p>The column function is also incredibly useful. It adds columns within a row, and it requires that you define a width for each column.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb27"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with fluid rows and columns</span></span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">fluidRow</span>(</span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">column</span>(<span class="st">"R1, C1, width = 3"</span>, <span class="at">width =</span> <span class="dv">3</span>),</span>
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">column</span>(<span class="st">"R1, C2, width = 9"</span>, <span class="at">width =</span> <span class="dv">9</span>)</span>
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb27-9"><a href="#cb27-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">fluidRow</span>(</span>
<span id="cb27-10"><a href="#cb27-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">column</span>(<span class="st">"R2, C1, width = 4"</span>, <span class="at">width =</span> <span class="dv">4</span>),</span>
<span id="cb27-11"><a href="#cb27-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">column</span>(<span class="st">"R2, C2, width = 4"</span>, <span class="at">width =</span> <span class="dv">4</span>),</span>
<span id="cb27-12"><a href="#cb27-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">column</span>(<span class="st">"R2, C3, width = 4"</span>, <span class="at">width =</span> <span class="dv">4</span>)</span>
<span id="cb27-13"><a href="#cb27-13" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb27-14"><a href="#cb27-14" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb27-15"><a href="#cb27-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-16"><a href="#cb27-16" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server function that does nothing</span></span>
<span id="cb27-17"><a href="#cb27-17" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb27-18"><a href="#cb27-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-19"><a href="#cb27-19" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the app object</span></span>
<span id="cb27-20"><a href="#cb27-20" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<div class="row">
<div class="col-sm-3">R1, C1, width = 3</div>
<div class="col-sm-9">R1, C2, width = 9</div>
</div>
<div class="row">
<div class="col-sm-4">R2, C1, width = 4</div>
<div class="col-sm-4">R2, C2, width = 4</div>
<div class="col-sm-4">R2, C3, width = 4</div>
</div>
</div>
</div>
</div>
<hr>
</section>
<section id="the-width-is-relative" class="level3">
<h3 class="anchored" data-anchor-id="the-width-is-relative">The width is relative</h3>
<p>The total width of columns within any given row should add up to 12. You can use the columns to place output objects like a plots or summary tables in specific places in your app.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<strong>3 + 9 = 12</strong>
<div class="row">
<div class="col-sm-3">
<div class="well">
R1, C1
<br>
width = 3
</div>
</div>
<div class="col-sm-9">
<div class="well">R1, C2, width = 9</div>
</div>
</div>
<strong>4 + 4 + 4 = 12</strong>
<div class="row">
<div class="col-sm-4">
<div class="well">R2, C1, width = 4</div>
</div>
<div class="col-sm-4">
<div class="well">R2, C2, width = 4</div>
</div>
<div class="col-sm-4">
<div class="well">R2, C3, width = 4</div>
</div>
</div>
</div>
</div>
</div>
<hr>
</section>
<section id="panels" class="level3">
<h3 class="anchored" data-anchor-id="panels">Panels</h3>
<p>You can use panels to group multiple elements into a single element that has its own properties.</p>
<p>This is especially important and useful for complex apps with a large number of inputs and outputs such that it might not be clear to the user where to get started.</p>
</section>
<section id="wellpanel" class="level3">
<h3 class="anchored" data-anchor-id="wellpanel"><code>wellPanel()</code></h3>
<p>The <code>wellpanel()</code> function groups elements into a grey well, or a box with rounded corners. This is a look you should be used to seeing in shiny apps by now.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb28"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with wellPanels</span></span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">wellPanel</span>( <span class="fu">fluidRow</span>(<span class="st">"Row 1"</span>) ),</span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">wellPanel</span>( <span class="fu">fluidRow</span>(<span class="st">"Row 2"</span>) ),</span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">wellPanel</span>( <span class="fu">fluidRow</span>(<span class="st">"Row 3"</span>) )</span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Define server function that does nothing</span></span>
<span id="cb28-11"><a href="#cb28-11" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb28-12"><a href="#cb28-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-13"><a href="#cb28-13" aria-hidden="true" tabindex="-1"></a><span class="co"># Create the app object</span></span>
<span id="cb28-14"><a href="#cb28-14" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<div class="well">
<div class="row">Row 1</div>
</div>
<div class="well">
<div class="row">Row 2</div>
</div>
<div class="well">
<div class="row">Row 3</div>
</div>
</div>
</div>
</div>
<hr>
</section>
<section id="panels-1" class="level3">
<h3 class="anchored" data-anchor-id="panels-1">Panels</h3>
<p>Shiny offers 12 different panels, but we’ll take a look at a small subset of them in this section, and then you’ll get to work with a few others in the exercises that follow.</p>
<div class="cell" data-layout-align="center">
</div>
</section>
<section id="sidebarpanel-and-mainpanel" class="level3">
<h3 class="anchored" data-anchor-id="sidebarpanel-and-mainpanel"><code>sidebarPanel()</code> and <code>mainPanel()</code></h3>
<p>We have made heavy use of <code>sidebarPanel()</code> and <code>mainPanel()</code> in our apps in this course. However we mostly stuck with their default widths.</p>
<p>The default width for a <code>sidebarPanel()</code> is 4 and for a <code>mainPanel()</code> is 8.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb29"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with default width sidebar</span></span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarLayout</span>(</span>
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarPanel</span>(</span>
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">strong</span>(<span class="st">"Sidebar"</span>),</span>
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true" tabindex="-1"></a> <span class="st">"Usually inputs go here, width = 4 by default"</span></span>
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true" tabindex="-1"></a> ),</span>
<span id="cb29-10"><a href="#cb29-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">mainPanel</span>(</span>
<span id="cb29-11"><a href="#cb29-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">strong</span>(<span class="st">"Main panel"</span>),</span>
<span id="cb29-12"><a href="#cb29-12" aria-hidden="true" tabindex="-1"></a> <span class="st">"Usually outputs go here, width = 8 by default"</span></span>
<span id="cb29-13"><a href="#cb29-13" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb29-14"><a href="#cb29-14" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb29-15"><a href="#cb29-15" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb29-16"><a href="#cb29-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-17"><a href="#cb29-17" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb29-18"><a href="#cb29-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-19"><a href="#cb29-19" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<div class="row">
<div class="col-sm-4">
<form class="well" role="complementary">
<strong>Sidebar</strong>
Usually inputs go here, width = 4 by default
</form>
</div>
<div class="col-sm-8" role="main">
<strong>Main panel</strong>
Usually outputs go here, width = 8 by default
</div>
</div>
</div>
</div>
</div>
<hr>
</section>
<section id="section-2" class="level3">
<h3 class="anchored" data-anchor-id="section-2"></h3>
<p>If you wanted to make an app where the <code>sidebar</code> and <code>mainPanel</code> are of equal width, so the app is split down the middle, you can specify a width argument to the <code>sidebarPanel()</code> and <code>mainPanel()</code> functions and set each to 6.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb30"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with default width sidebar</span></span>
<span id="cb30-4"><a href="#cb30-4" aria-hidden="true" tabindex="-1"></a><span class="fu">fluidPage</span>(</span>
<span id="cb30-5"><a href="#cb30-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarLayout</span>(</span>
<span id="cb30-6"><a href="#cb30-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarPanel</span>(<span class="st">"Sidebar with width = 6"</span>, <span class="at">width =</span> <span class="dv">6</span>),</span>
<span id="cb30-7"><a href="#cb30-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">mainPanel</span>(<span class="st">"Main panel with width = 6"</span>, <span class="at">width =</span> <span class="dv">6</span>)</span>
<span id="cb30-8"><a href="#cb30-8" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb30-9"><a href="#cb30-9" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb30-10"><a href="#cb30-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-11"><a href="#cb30-11" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb30-12"><a href="#cb30-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-13"><a href="#cb30-13" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<form class="well" role="complementary">Sidebar with width = 6</form>
</div>
<div class="col-sm-6" role="main">Main panel with width = 6</div>
</div>
</div>
</div>
</div>
<hr>
</section>
<section id="titlepanel" class="level3">
<h3 class="anchored"><code>titlePanel()</code></h3>
<p>The <code>titlePanel()</code> is used to create a panel containing an application title. Often it makes sense to include this panel outside the <code>sidebarLayout()</code>. But in addition to the title on the page, youmight want to also change the text that shows up on the browser tab for our app, especially if our title is long.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb31"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with title panel</span></span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb31-5"><a href="#cb31-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">titlePanel</span>(<span class="st">"My awesome app"</span>),</span>
<span id="cb31-6"><a href="#cb31-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarLayout</span>(</span>
<span id="cb31-7"><a href="#cb31-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarPanel</span>(<span class="st">"Some inputs"</span>),</span>
<span id="cb31-8"><a href="#cb31-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">mainPanel</span>(<span class="st">"Some outputs"</span>)</span>
<span id="cb31-9"><a href="#cb31-9" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb31-10"><a href="#cb31-10" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb31-11"><a href="#cb31-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-12"><a href="#cb31-12" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb31-13"><a href="#cb31-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb31-14"><a href="#cb31-14" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<h2 class="anchored" data-anchor-id="titlepanel">My awesome app</h2>
<div class="row">
<div class="col-sm-4">
<form class="well" role="complementary">Some inputs</form>
</div>
<div class="col-sm-8" role="main">Some outputs</div>
</div>
</div>
</div>
</div>
<hr>
</section>
<section id="titlepanel-with-windowtitle" class="level3">
<h3 class="anchored"><code>titlePanel()</code> with <code>windowTitle</code></h3>
<p>To customize this text you specify the <code>windowTitle</code> argument in the <code>titlePanel()</code>, which is by default equal to the application title. For example, your application title might be “Movie browser, 1970 to 2014”, but you might just want to make your window title “Movies”.</p>
<div class="cell" data-layout-align="center">
<div class="sourceCode" id="cb32"><pre class="sourceCode r cell-code code-with-copy"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(shiny)</span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Define UI with title panel and window title</span></span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a>ui <span class="ot"><-</span> <span class="fu">fluidPage</span>(</span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">titlePanel</span>(<span class="st">"Movie browser, 1970 to 2014"</span>,</span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true" tabindex="-1"></a> <span class="at">windowTitle =</span> <span class="st">"Movies"</span>),</span>
<span id="cb32-7"><a href="#cb32-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarLayout</span>(</span>
<span id="cb32-8"><a href="#cb32-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">sidebarPanel</span>(<span class="st">"Some inputs"</span>),</span>
<span id="cb32-9"><a href="#cb32-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">mainPanel</span>(<span class="st">"Some outputs"</span>)</span>
<span id="cb32-10"><a href="#cb32-10" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb32-11"><a href="#cb32-11" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb32-12"><a href="#cb32-12" aria-hidden="true" tabindex="-1"></a>server <span class="ot"><-</span> <span class="cf">function</span>(input, output, session) {}</span>
<span id="cb32-13"><a href="#cb32-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb32-14"><a href="#cb32-14" aria-hidden="true" tabindex="-1"></a><span class="fu">shinyApp</span>(<span class="at">ui =</span> ui, <span class="at">server =</span> server)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="container-fluid">
<h2 class="anchored" data-anchor-id="titlepanel-with-windowtitle">Movie browser, 1970 to 2014</h2>
<div class="row">
<div class="col-sm-4">
<form class="well" role="complementary">Some inputs</form>
</div>
<div class="col-sm-8" role="main">Some outputs</div>
</div>
</div>
</div>