About this workshop

This document serves as slides and script for the workshop Interactive Data Analysis with Shiny taught by Paul C. Bauer and Jonas Lieth. Original material is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC 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. If you have feedback or discover errors/dead links please let us know via email (mail@paulcbauer.de/Jonas.Lieth@gesis.org) or by submitting an issue on github. And make sure to install all the necessary packages before you use the script.



1 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
    • Previously: PhD at the University of Bern; research/postdoctoral fellow at the MZES, the EUI (Florence, Italy)
    • My research (Google Scholar, Github)
      • 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) and Shiny apps (e.g. gretan) for research
    • Contact: jonas.lieth@gesis.org; Website; GitHub

2 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?)

3 Contact & Outline & Dates

  • Important: 2nd time we teach workshop/material
  • Course outline/content/dates: (see toc on the left)
Tuesday, 23.07
10:00-11:00 Welcome and introduction
11:00-11:15 Coffee break
11:15-12:00 Your (first) Shiny app
12:00-13:00 Lunch break
13:00-14:15 The front end: Designing the user interface
14:15-14:30 Coffee break
14:30-16:00 Tutorials for the UI
Wednesday, 24.07.
10:00-11:00 Introduction to reactive programming
11:00-11:15 Coffee break
11:15-12:00 Tutorials for reactive programming
12:00-13:00 Lunch break
13:00-14:15 Advanced reactive programming
14:15-14:30 Coffee break
14:30-16:00 Tutorials for reactive programming
Thursday, 25.07
10:00-11:00 Visualization with ggplot2 and Shiny
11:00-11:15 Coffee break
11:15-12:00 Tutorials for visualization
12:00-13:00 Lunch break
13:00-14:15 Testing and deployment
14:15-14:30 Coffee break
14:30-16:00 Tutorials for deployment
Friday, 26.07.
10:00-11:00 Good practices when building your own app
11:00-11:15 Coffee break
11:15-12:00 Build your own app: Design and UI
12:00-13:00 Lunch break
13:00-14:15 Build your own app: Construct the reactive graph
14:15-14:30 Coffee break
14:30-15:30 Build your own app: Strengthen & deploy
15:30-16:00 Exhibit: Show off your new Shiny app

4 Script & 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). 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 deploy 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
  • 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!

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.
# install.packages("pacman")

pacman::p_load(c(
   apexcharter,
   broom,
   datasauRus,
   gganimate,
   gifski,
   gt,
   gtsummary,
   haven,
   highcharter,
   htmltools,
   httpuv,
   kableExtra,
   leaflet,
   listviewer,
   modelsummary,
   plotly,
   png,
   profvis,
   reactlog,
   rsconnect,
   sf,
   shiny,
   shinylive,
   tidyverse
))

9 Helpful resources

  1. Shiny user showcase
  2. Shiny feature demos
  3. Shiny widget gallery
  4. R Shiny for Enterprise Application Development: 6 Lessons for Building Shiny Apps
  5. Shiny apps by Dimiter Toshkov

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

  1. Creators: Core contributors and thousands of package authors.↩︎

  2. Creators: https://github.com/tidyverse/ggplot2↩︎

  3. Creators: https://github.com/plotly/plotly.js; https://github.com/ropensci/plotly↩︎