Overview

Hex sticker, text: ShinyIntro

Shiny lets you make web applications that do anything you can code in R. For example, you can share your data analysis in a dynamic way with people who don't use R, collect and visualize data, or even make data aRt.

While there is a wealth of material available on the internet to help you get started with Shiny, it can be difficult to see how everything fits together. This class will take a predominantly live coding approach, rather than a lecture-only approach, so you can code along with the instructor and deal with the inevitable bugs and roadblocks together.

This class will teach you the basics of Shiny app programming, giving you skills that will form the basis of almost any app you want to build. By the end of the class, you will have created a custom app that collects and saves data, allows users to dynamically visualize the data, and produces downloadable reports.

0.1 Installing shinyintro

To install the class package, which will provide you with a copy of all of the shiny apps we'll use for demos and the basic template, paste the following code into the console in RStudio. See Appendix A for help installing R and RStudio.

# you may have to install devtools first with 
# install.packages("devtools")

devtools::install_github("debruine/shinyintro")

The class package lets you access the book or run the demo apps offline.

shinyintro::book()
shinyintro::app("first_demo")

You can also clone the demo apps.

shinyintro::clone("basic_template", "myapps/newapp")

0.2 Example Apps

The following are some diverse examples of Shiny apps that the instructor has made.

  • Word Cloud Create a word cloud from text and customize its appearance. Created during the live-coding event at Hack Your Data Beautiful.
  • Faux Simulate data with a specified factorial design.
  • Plot Demo Simulate data from a 2×2 factorial design and visualize it with 6 different plot styles.
  • Simulating for LMEM companion to Understanding mixed effects models through data simulation (DeBruine & Barr, AMPPS 2021)
  • Scienceverse is an ambitious (but in-progress) app for creating machine-readable descriptions of studies and human-readable summaries.

0.2.1 Computing

To participate in the hands-on exercises, you are strongly encouraged to use a computer with the most recent version of R installed. Participants are also encouraged to download and install RStudio, a front-end for R that makes it easier to work with. This software is free and available for Windows, Mac, and Linux platforms.

0.2.2 What experience do I need?

You need to have basic familiarity with R, including data import, data processing, visualization, and functions and control structures (e.g., if/else). Instruction will be done using RStudio. Some familiarity with ggplot2 and dplyr would be useful. You definitely do not need to be an expert coder, but the following code should not be challenging to understand.

library(ggplot2)

pets <- read.csv("pets.csv")

dv <- sample(c("score", "weight"), 1)

if (dv == "score") {
  g <- ggplot(pets, aes(pet, score, fill = country))
} else if (dv == "weight") {
  g <- ggplot(pets, aes(pet, weight, fill = country))
}

g + geom_violin(alpha = 0.5)

If you want to brush up on your R (especially tidyverse), and also gain familiarity with the instructor's teaching style, the book Applied Data Skills provides a good overview.

0.3 Further Resources

There are a lot of great resources online to reinforce or continue your learning about Shiny. I advise going back to learning materials periodically because things that don't make sense the first (or second or third...) time around often click after you've had some experience.