# install.packages('pacman')
library(pacman)
p_load('gt', 'gtsummary',
'modelsummary', 'gifski', 'png', 'datasauRus', 'ggplot2', 'gganimate', 'dplyr',
'shiny', 'htmltools', 'bs4Dash', 'fresh', 'waiter', 'shinyWidgets', 'Guerry',
'sf', 'tidyr', 'RColorBrewer', 'viridis', 'leaflet', 'plotly', 'jsonlite',
'GGally', 'datawizard', 'parameters', 'performance', 'ggdark', 'reactlog',
'profvis', 'rsconnect', 'whereami', 'DT')
About this workshop
1 About us (Paul & Jonas)
- Paul
- Currently MZES Research fellow (University of Mannheim)
- Previously… University of Bern (PhD, 2015), European University Institute (Postdoc, 15’-17’)
- My research interests: political sociology & methodology [see Google Scholar)
- Started R around 2009, first shiny apps ~2015 for teaching/research purposes (e.g., here and here)
- Contact:
mail@paulcbauer.de
; www.paulcbauer.de; Twitter; Github
- Jonas
- Currently a research fellow at GESIS’ survey data curation (SDC) department
- Constantly learning about R and Shiny since 2020
- Interested in social geography, spatial analysis and computational text analysis
- Contact:
jonas.lieth@gesis.org
; GitHub: JsLth
2 Your turn
- Let’s check our the survey results…
- Name?
- Affiliation? Country?
- What do you want to use Shiny for? (or research questions?)
3 Contact & Outline & Dates
- Important: 1st time we teach workshop/material
- Course outline/content/dates: (see toc on the left)
- Day 1: Introduction to Shiny
- 13:00 - 14:00: Welcome and Introduction (1)
- 14:00 - 15:00: Introduction (2)
- 15:00 - 15:30: Coffee break
- 15:30 - 16:30: User Interface (UI): Designing the front end (1)
- 16:30 - 17:30: User Interface (UI): Designing the front end (2) [Introduction tab]
- Day 2: Reactive programming
- 13:00 - 14:00: Server: Reactive programming (1)
- 14:00 - 15:00: Server: Reactive programming (2) [Tabulate data tab]
- 15:00 - 15:30: Coffee break
- 15:30 - 16:30: Modelling and visualizing data (1)
- 16:30 - 17:30: Modelling and visualizing data (2) [Modelling data tab]
- Day 3: Develop your app
- 13:00 - 14:00: Mapping data & advanced visualization (1)
- 14:00 - 15:00: Mapping data & advanced visualization (2) [Mapping data tab]
- 15:00 - 15:30: Coffee break
- 15:30 - 16:30: Theming & styling
- 16:30 - 17:30: Strengthen & Deploy
- Day 1: Introduction to Shiny
4 Script & material
- Literature: See syllabus.
- Website/script: https://bookdown.org/paul/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. If not we’ll share the files.
- Full screen: F11
- Navigation: TOCs on left and right
- Search document (upper left)
- Document generated with quarto
- Motivation: Have a go-to script for participants (and ourselves!)
- Content: Mixture of theory, lab sessions, exercises and pure code examples for discussion
5 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 launch their Shiny application
6 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
- We see the Shiny app how its mostly consumed ;-) (on a screen)
- 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!
7 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):
- Wickham (2021): 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/.
8 Software we will use
- Open-source software! (Q: Why?)
- R (R Core Team 2023)1
- only viable competitor is Python
- Install the necessary packages using the code below.
- Shiny (Chang et al. 2022; Wickham 2021)
- Ggplot22 (Wickham 2016)
- Plotly3 (Sievert 2020)
- Note: Ideally cite the software you use in your research especially when it is open-source (e.g., run
citation("ggplot2")
)
9 Helpful resources
References
Chang, Winston, Joe Cheng, JJ Allaire, Carson Sievert, Barret Schloerke, Yihui Xie, Jeff Allen, Jonathan McPherson, Alan Dipert, and Barbara Borges. 2022. Shiny: Web Application Framework for r. https://CRAN.R-project.org/package=shiny.
R Core Team. 2023. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Sievert, Carson. 2020. Interactive Web-Based Data Visualization with r, Plotly, and Shiny. Chapman; Hall/CRC. https://plotly-r.com.
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.
———. 2021. Mastering Shiny. " O’Reilly Media, Inc.".
Footnotes
Creators: Core contributors and thousands of package authors.↩︎
Creators: https://github.com/tidyverse/ggplot2↩︎
Creators: https://github.com/plotly/plotly.js; https://github.com/ropensci/plotly↩︎