Site icon R-bloggers

A Gentle Introduction to R Shiny

[This article was first published on business-science.io, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This article is part of a R-Tips Weekly, a weekly video tutorial that shows you step-by-step how to do common R coding tasks.


What if you could turn your #datascience​ analysis into a web application? You can do EXACTLY that with R​ Shiny​.

R Shiny is an amazing framework built to convert your data analysis into a web app – FAST! Create amazing applications your business can use in hours (not months!).

Here are the links to get set up. ????


(Click image to play tutorial)

Shiny Explorer App

In this R-Tip, you create an AWESOME Correlation Plot Heatmap that can be used for fast Exploratory Data Analysis (EDA). This application uses:

The Shiny App with Correlation Heat Map

Why use R Shiny?

I get this question a ton: Why R Shiny vs Tableau or PowerBI or any other “dashboarding” tool?

R Shiny is much more than a dashboarding tool.

I love showing off this app. Nostradamus is an example of the high-end of what you can accomplish when you learn R Shiny and time series forecasting with Modeltime. Nostradamus is an Auto-Forecasting App that makes 28 machine learning models on the fly and combines the best into an ensemble. The forecasting approach adjusts automatically. Internally the app uses:

Learning Shiny for Your Career

The key differences between Shiny and Tableau are important to understand as they relate to the concept of the Full-Stack Data Scientist (a data scientist that can make and distribute web applications powered with data science). The bottom line is that R Shiny allows businesses to truly scale decisions beyond a simple dashboard.

This is why I highly recommend learning R Shiny for your career. Businesses need apps that can forecast sales demand, predict customer churn, and distribute actionable insights real-time. Shiny does all of this.

But first thing first – Let’s create your First Shiny App!

Creating Your First Shiny App

R Shiny can be intimidating. If this is your first time building an app, I strongly recommend watching the YouTube Video – Gentle Intro to R Shiny Apps (11 min). It will help immensely.

PRO TIP

As you go through this tutorial, I’ve added the “Shinyverse” to my Ultimate R Cheatsheet (see page 2). The most important part is at the top, which includes links the the key R packages that make up an expanding ecosystem of shiny R packages. ????

How does R Shiny work?

At it’s core, R Shiny is a web framework that combines a User Interface (controls app layout and appearance) with a Server (runs R, controls app functionality).

The User Interface (UI)

Think of the UI as the scaffolding and theming elements that position your app’s output and make it look amazing!

Shiny Inputs


We can add shiny inputs to an app. These are the elements that your user interacts with. They tell your server (discussed next) when something is happening.

When we run the app, the shiny selectInput() generates this dropdown in our UI.

The Server (R Code is Run Here)

Think of the Server as where your R Code runs when the user interacts with your app.

Reactivity & Observers

Inside the server, R Shiny uses a concept called “Reactivity”. I teach this concept in-depth using many examples in my Shiny Dashboard Course and Shiny Developer with AWS Course.

What we are doing: We store reactive values and modify them inside of observers.

What this means:


Then, any functions downstream that use the rv$data_set will fire, updating the data accordingly.


Finally, our app’s UI then updates because we have an outputPlotly() in our UI that references the “corrplot” on our server.


Now, when we use the Shiny App dropdowns, our app fires and the datasets change on the fly!

In Summary
You just built your first Shiny App! Congratulations.

You should be proud.

But, what if you want to build more powerful applications?

This could be a challenge. You’ll need to learn a ton, and this will take a long time. Plus, you might struggle and quit.

The number one reason that people quit: They get an error that they can’t figure out.

Errors stop your progress… Grinding to a halt.

What if there was a program that took the guess-work out of learning data science and made it impossible to fail?




???? Top R-Tips Tutorials you might like:


To leave a comment for the author, please follow the link and comment on their blog: business-science.io.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.