-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-workshop.qmd
254 lines (183 loc) · 10.4 KB
/
01-workshop.qmd
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
---
title: "About this workshop"
---
```{r dependencies, include=FALSE, cache=FALSE}
packages <- unique(renv::dependencies()$Package)
packages <- packages[packages!="R"]
# assert that all packages are available
loadable <- vapply(packages, FUN.VALUE = logical(1), requireNamespace)
# install missing dependencies
if (!all(loadable)) {
pacman::p_install(packages[!loadable])
}
exclude <- c(
"pander", "stringr", "renv", "rmarkdown", "knitr", "htmlwidgets", "purrr",
"rnaturalearthdata", "smoothr", "readr", "tidyr", "dplyr", "ggplot2",
"pacman", "quarto"
)
packages <- sort(setdiff(packages, exclude))
library(dplyr)
library(purrr)
library(htmltools)
library(pander)
```
This document serves as slides and script for the workshop ***Interactive Data Analysis with Shiny*** taught by [Paul C. Bauer](http://paulcbauer.eu/) <a href='https://twitter.com/p_c_bauer' class='fa fa-twitter' target='_blank'></a> and [Jonas Lieth](). Original material is licensed under a [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](https://creativecommons.org/licenses/by-nc-sa/4.0/) license. Where we draw on other authors material other licenses may apply (see references in the syllabus as well as the citations and links in the script). For potential future versions of this material see the [github repository](https://github.com/paulcbauer/shiny_workshop/). If you have feedback or discover errors/dead links please let us know via email ([email protected]/[email protected]) or by submitting an issue on github. And make sure to [install all the necessary packages]() before you use the script.
<br><br>
## About us (Paul & Jonas)
- Paul
+ Instructor at University of Freiburg (Department of politics), Postdoc at LMU Munich (statistics department, Frauke Kreuter), External fellow at [MZES](https://www.mzes.uni-mannheim.de/d7/en)
+ Previously: PhD at the [University of Bern](http://www.unibe.ch/index_eng.html); research/postdoctoral fellow at the [MZES](https://www.mzes.uni-mannheim.de/d7/en), the [EUI](https://www.eui.eu/) (Florence, Italy)
+ My [research](https://www.paulcbauer.de) ([Google Scholar](https://scholar.google.ch/citations?user=hw-b-MkAAAAJ&hl=en), [Github](https://github.com/paulcbauer))
+ **Substantive**: Political sociology & comparative politics (Trust, polarization, social media, fake news)
+ **Methods/data**: Causal inference, experiments, text data, data visualization, machine learning, big data (Google trends, Twitter)
- Jonas
- Currently a research fellow at GESIS' survey data curation (SDC) department
- PhD student interested in social geography, spatial data science, and computational text analysis
- Developing R packages (e.g. [`r311`](https://github.com/JsLth/r311)) and Shiny apps (e.g. [`gretan`](https://github.com/JsLth/gretan)) for research
- Contact: `[email protected]`; [Website](https://www.gesis.org/institut/ueber-uns/mitarbeitendenverzeichnis/person/Jonas.Lieth); [GitHub](https://github.com/JsLth)
## Your turn
- Let's check our the survey results...
1. Name?
2. Affiliation? Country?
3. What do you want to use Shiny for? (or research questions?)
<!--
Below take too long for short workshop
4. Previous experience with R?
5. Why are you interested in this
workshop?
-->
## Contact & Outline & Dates
- **Important**: 2nd time we teach workshop/material
- **Course outline/content/dates:** (see toc on the left)
```{r, echo=FALSE}
schedule <- tribble(
~time, ~name, ~file, ~header,
"Tuesday, 23.07", "Introduction to Shiny", NA, TRUE,
"10:00-11:00", "Welcome and introduction", "01-workshop.html", FALSE,
"11:00-11:15", "Coffee break", NA, FALSE,
"11:15-12:00", "Your (first) Shiny app", "02-introduction.html", FALSE,
"12:00-13:00", "Lunch break", NA, FALSE,
"13:00-14:15", "The front end: Designing the user interface", "03-user-interface.html", FALSE,
"14:15-14:30", "Coffee break", NA, FALSE,
"14:30-16:00", "Tutorials for the UI", "03-user-interface.html", FALSE,
"Wednesday, 24.07.", "Reactive programming", NA, TRUE,
"10:00-11:00", "Introduction to reactive programming", "04-server-reactive-programming-i.html", FALSE,
"11:00-11:15", "Coffee break", NA, FALSE,
"11:15-12:00", "Tutorials for reactive programming", "04-server-reactive-programming-i.html", FALSE,
"12:00-13:00", "Lunch break", NA, FALSE,
"13:00-14:15", "Advanced reactive programming", "05-server-reactive-programming-ii.html", FALSE,
"14:15-14:30", "Coffee break", NA, FALSE,
"14:30-16:00", "Tutorials for reactive programming", "05-server-reactive-programming-ii.html", FALSE,
"Thursday, 25.07", "Finetuning and deployment", NA, TRUE,
"10:00-11:00", "Visualization with ggplot2 and Shiny", "06-visualization.html", FALSE,
"11:00-11:15", "Coffee break", NA, FALSE,
"11:15-12:00", "Tutorials for visualization", "06-visualization.html", FALSE,
"12:00-13:00", "Lunch break", NA, FALSE,
"13:00-14:15", "Testing and deployment", "07-deployment.html", FALSE,
"14:15-14:30", "Coffee break", NA, FALSE,
"14:30-16:00", "Tutorials for deployment", "07-deployment.html", FALSE,
"Friday, 26.07.", "Build your own app", NA, TRUE,
"10:00-11:00", "Good practices when building your own app", "08-build-your-own.html", FALSE,
"11:00-11:15", "Coffee break", NA, FALSE,
"11:15-12:00", "Build your own app: Design and UI", "08-build-your-own.html", FALSE,
"12:00-13:00", "Lunch break", NA, FALSE,
"13:00-14:15", "Build your own app: Construct the reactive graph", "08-build-your-own.html", FALSE,
"14:15-14:30", "Coffee break", NA, FALSE,
"14:30-15:30", "Build your own app: Strengthen & deploy", "08-build-your-own.html", FALSE,
"15:30-16:00", "Exhibit: Show off your new Shiny app", "08-build-your-own.html", FALSE
)
schedule <- pmap(schedule, function(time, name, file, header) {
colspan <- NULL
if (header) {
colspan <- 2
time <- tags$b(time)
}
cell1 <- tags$td(time, colspan = colspan, valign = "middle")
cell2 <- NULL
if (!header) {
if (is.na(file)) {
name <- tags$i(name)
} else {
name <- tags$a(
name,
href = file.path("https://paulcbauer.github.io/shiny_workshop", file)
)
}
cell2 <- tags$td(name, valign = "middle")
}
tags$tr(valign = "top", cell1, cell2)
})
schedule <- tags$table(tags$tbody(schedule), cellpadding = 0, cellspacing = 0)
schedule <- as.character(schedule)
cat(schedule, file = "resources/schedule.html")
pander(schedule)
```
## Script & material {#material}
- **Literature**: See syllabus.
- **Website/script**: https://paulcbauer.github.io/shiny_workshop/
- Find it: Google "shiny paul jonas"
- Document = slides + script (Zoom in/out with `STRG + mousewheel`)
- **Code**: can all be found in the script
- **Data**: can usually be downloaded over links in the script or from github (e.e., see [here for the data](https://github.com/paulcbauer/shiny_workshop/tree/main/app)). If not we'll share the files.
- Full screen: F11
- **Navigation**: TOCs on left and right
- Search document (upper left)
- Document generated with [quarto](https://quarto.org/)
- **Motivation**: Have a go-to script for participants (and ourselves!)
- **Content**: Mixture of theory, lab sessions, exercises and pure code examples for discussion
## Strategy & Goals
- **Strategy**: From the simple to the complex, slowly building up a complex Shiny app that includes various aspects (tabulate data, modelling and descriptive graphs, mapping)
- **Goals**: By the end of the course participants will:
- know what the structure of a Shiny application looks like
- understand the basics of reactive programming for interactive data analysis and visualization
- be comfortable to use R Shiny to build their own interactive applications
- have learned about different ways to deploy their Shiny application
## Online vs. offline
* **Negative**
+ Screen fatigue
+ Can't run around to check your code
+ Less engaging, less social
+ Voice
+ Screen sharing &less screen space than classroom
* **Positive**
+ We see the Shiny app how its mostly consumed
;-) (on a screen)
+ Remember: "How is your Shiny app consumed (smartphone)?"
+ Participation from everywhere
* **Rule(s)**: Please keep your camera online if possible!
+ Distracting animals/children/partners are a welcome distraction!
+ Yawning, leaving, looking bored etc. allowed!
+ Use a virtual background if you like!
+ Any questions are welcome!
## Recommended readings
- **Important**: Our workshop does not require any prior reading.
- However, our schedule is primarily based on two textbooks which we generally recommend for further reading (see references on website):
- @wickham2021mastering: Mastering Shiny: Build Interactive Apps, Reports, and Dashboards Powered by R. Accessible online at: https://mastering-shiny.org/.
- Fay, Colin, Rochette, Sébastien, Guyader, Vincent, and Girard, Cervan (2022): Engineering Production-Grade Shiny Apps. Accessible online at: https://engineering-shiny.org/.
## Software we will use
- Open-source software! (Q: Why?)
- R [@rcoreteam2023]^[Creators: [Core contributors](https://www.r-project.org/contributors.html) and thousands of package authors.]
- only viable competitor is Python
- Install the necessary packages using the code below.
```{r workshop-1, echo=FALSE, results='asis', cache=FALSE}
options(width = 300)
# format pacman string
pkg_fmt <- paste0(
"# install.packages(\"pacman\")\n\n",
"pacman::p_load(c(\n",
paste(paste(" ", packages), collapse = ",\n"),
"\n))"
)
pkg_fmt <- sprintf("```{r}\n%s\n```", pkg_fmt)
pander::pander(pkg_fmt)
```
- Shiny [@chang2020; @wickham2021mastering]
- ggplot2^[Creators: https://github.com/tidyverse/ggplot2] [@wickham2016]
* plotly^[Creators: https://github.com/plotly/plotly.js; https://github.com/ropensci/plotly] [@sievert2020]
* Note: Ideally cite the software you use in your research especially when it is open-source (e.g., run `citation("ggplot2")`)
## Helpful resources
1. [Shiny user showcase](https://shiny.posit.co/r/gallery/#user-showcase)
2. [Shiny feature demos](https://shiny.posit.co/r/gallery/#feature-demos)
3. [Shiny widget gallery](https://shiny.posit.co/r/gallery/widgets/widget-gallery/)
4. [R Shiny for Enterprise Application Development: 6 Lessons for Building Shiny Apps](https://appsilon.com/why-you-should-use-r-shiny-for-enterprise-application-development/#anchor-7)
5. [Shiny apps by Dimiter Toshkov](http://www.dimiter.eu/Visualizations.html)