<commit_before>---
layout: post
title: "Building Shiny apps - an interactive tutorial"
date: 2015-12-07 10:00:00 -0700
tags: [professional, rstats, r, r-bloggers, shiny, tutorial]
---

> This tutorial was originally developed for the [STAT545](http://stat545-ubc.github.io) course at UBC, but I decided to publish it shortly afterwards so that more people can benefit from it. This version also contains new sections the original lecture didn't have.

Shiny is a package from RStudio that can be used to build interactive web pages with R. While that may sound scary because of the words "web pages", it's geared to R users who have 0 experience with web development, and you do not need to know any HTML/CSS/JavaScript.

You can do quite a lot with Shiny: think of it as an easy way to make an interactive web page, and that web page can seamlessly interact with R and display R objects (plots, tables, of anything else you do in R). To get a sense of the wide range of things you can do with Shiny, you can visit [ShowMeShiny.com](http://www.showmeshiny.com/), which is a gallery of user-submitted Shiny apps. 

This tutorial is a hands-on activity complement to a set of [presentation slides](https://docs.google.com/presentation/d/1dXhqqsD7dPOOdcC5Y7RW--dEU7UfU52qlb0YD3kKeLw/edit?usp=sharing) for learning how to build Shiny apps. In this activity, we'll walk through all the steps of building a Shiny app using a dataset that lets you explore the products available at the BC Liquor Store. The final version of the app, including a few extra features that are left as exercises for the reader, [can be seen here](http://daattali.com/shiny/bcl/). Any activity deemed as an exercise throughout this tutorial is not mandatory for building our app, but they are good for getting more practice with Shiny.

As an added tutorial, I highly recommend the [official Shiny tutorial](http://shiny.rstudio.com/tutorial/). RStudio also provides a [handy cheatsheet](https://www.rstudio.com/resources/cheatsheets/) to remember all the little details after you already learned the basics.

**Exercise:** Visit [ShowMeShiny.com](http://www.showmeshiny.com/) and click through some of the showcased apps. Get a feel for the wide range of things you can do with Shiny.

## Table of contents

- [Before we begin](#before-we-begin)
- [Shiny app basics](#shiny-app-basics)
- [Create an empty Shiny app](#create-an-empty-shiny-app)
- [Load the dataset](#load-the-dataset)
- [Build the UI](#build-the-ui)
- [Checkpoint: what our app looks like after implementing the UI](#checkpoint-what-our-app-looks-like-after-implementing-the-ui)
- [Implement server logic to create outputs](#implement-server-logic-to-create-outputs)
- [Reactivity 101](#reactivity-101)
- [Using uiOutput() to create UI elements dynamically](#using-uioutput-to-create-ui-elements-dynamically)
- [Final Shiny app code](#final-shiny-app-code)
- [Share your app with the world](#share-your-app-with-the-world)<commit_msg>shiny apps tutorial: add time estimate<commit_after>---
layout: post
title: "Building Shiny apps - an interactive tutorial"
date: 2015-12-07 10:00:00 -0700
tags: [professional, rstats, r, r-bloggers, shiny, tutorial]
---

> This tutorial was originally developed for the [STAT545](http://stat545-ubc.github.io) course at UBC, but I decided to publish it shortly afterwards so that more people can benefit from it. This version also contains new sections the original lecture didn't have.

Shiny is a package from RStudio that can be used to build interactive web pages with R. While that may sound scary because of the words "web pages", it's geared to R users who have 0 experience with web development, and you do not need to know any HTML/CSS/JavaScript.

You can do quite a lot with Shiny: think of it as an easy way to make an interactive web page, and that web page can seamlessly interact with R and display R objects (plots, tables, of anything else you do in R). To get a sense of the wide range of things you can do with Shiny, you can visit [ShowMeShiny.com](http://www.showmeshiny.com/), which is a gallery of user-submitted Shiny apps. 

This tutorial is a hands-on activity complement to a set of [presentation slides](https://docs.google.com/presentation/d/1dXhqqsD7dPOOdcC5Y7RW--dEU7UfU52qlb0YD3kKeLw/edit?usp=sharing) for learning how to build Shiny apps. In this activity, we'll walk through all the steps of building a Shiny app using a dataset that lets you explore the products available at the BC Liquor Store. The final version of the app, including a few extra features that are left as exercises for the reader, [can be seen here](http://daattali.com/shiny/bcl/). Any activity deemed as an exercise throughout this tutorial is not mandatory for building our app, but they are good for getting more practice with Shiny. 

This tutorial should take approximately an hour to complete. If you want even more practice, another great tutorial I highly recommend is the [official Shiny tutorial](http://shiny.rstudio.com/tutorial/). RStudio also provides a [handy cheatsheet](https://www.rstudio.com/resources/cheatsheets/) to remember all the little details after you already learned the basics.

**Exercise:** Visit [ShowMeShiny.com](http://www.showmeshiny.com/) and click through some of the showcased apps. Get a feel for the wide range of things you can do with Shiny.

## Table of contents

- [Before we begin](#before-we-begin)
- [Shiny app basics](#shiny-app-basics)
- [Create an empty Shiny app](#create-an-empty-shiny-app)
- [Load the dataset](#load-the-dataset)
- [Build the UI](#build-the-ui)
- [Checkpoint: what our app looks like after implementing the UI](#checkpoint-what-our-app-looks-like-after-implementing-the-ui)
- [Implement server logic to create outputs](#implement-server-logic-to-create-outputs)
- [Reactivity 101](#reactivity-101)
- [Using uiOutput() to create UI elements dynamically](#using-uioutput-to-create-ui-elements-dynamically)
- [Final Shiny app code](#final-shiny-app-code)
- [Share your app with the world](#share-your-app-with-the-world)
{'fraction_non_alphanumeric': 0.08900609856601285, 'fraction_numerical': 0.013186088676446349, 'mean_word_length': 4.551692589204025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5893695', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1688, 'n_words': 789}