Skip to content

How to create interactive web applications in RStudio IDE using Shiny

So you can already create fantastic visualizations in R with packages like ggplot, but why not take it a step further and make your visualizations interactive using R's Shiny library? Using Shiny, you can create all sorts of web-based interactive apps just using R code. 

Check out this gallery for examples of some of the cool things you can do with shiny.

If you need a primer on R programming, check out the free "Introduction to R" course on Big Data University!

Creating your first Shiny application with RStudio IDE:


1. Open RStudio IDE, from the menu at the top of Data Scientist Workbench:


 2. Create a New Project. You may be prompted to save your 


3. Choose "New Directory" to create your application in a new folder.
.

 4. Choose "Shiny Web Application".
   
 
5. Enter a Directory name, like "myshinyapp" and click "Create Project". Your Directory name will also be the name of the folder where your shiny app resides.
 

 6. You will notice that RStudio IDE has created two sample .R script files for you: ui.R and server.R.

The ui.R contains scripts needed to create the user interface of your app. This includes scripts for your graphs, slider bars, text boxes, etc. Actions that the user performs in the shiny app are captured here.

The server.R contains scripts needed to run in the background that tells R what to do with the inputs received from ui.R. After processing the user inputs, server.R sends the outputs back to ui.R, which updates its display.

Let's go ahead and run the app, by clicking on "Run App", which should create a pop-up window. You may need to prevent your browser from blocking the pop-up window.
  

 7. Hurray! You've launched your first Shiny app! Try move the slider bar on the left-hand side and see how it changes the histogram.
 

8. Once you're done using the app, you probably want to stop it so it stops running. To stop your app, click on the red "Stop" sign:




Learning how to customize your own Shiny apps:


Creating Shiny apps is easy, and there are some excellent tutorials to learn how to create some fancy interactive applications using Shiny.

Check out the official Shiny tutorials to learn more: http://shiny.rstudio.com/tutorial/

Feedback and Knowledge Base