Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconData Sciencebreadcumb forward arrow iconR Shiny Tutorial: How to Make Interactive Web Applications in R

R Shiny Tutorial: How to Make Interactive Web Applications in R

Last updated:
16th Mar, 2020
Views
Read Time
6 Mins
share image icon
In this article
Chevron in toc
View All
R Shiny Tutorial: How to Make Interactive Web Applications in R

Introduction

In this modern technological era, various apps are available for all of us –from tracking our fitness level, sleep to giving us the latest information about the stock markets. Apps like Robinhood, Google Fit and Workit seem so amazingly useful because they use real-time data and statistics. As R is a frontrunner in the field of statistical computing and programming, developers need a system to use its power to build apps. Learn more about R Programming.

This is where R Shiny comes to save the day. In this, R Shiny tutorial, you will come to know the basics. 

What is R Shiny?

Shiny is an R package that was developed for building interactive web applications in R. Using this, you can create web applications utilizing native HTML and CSS code along with R Shiny code. You can build standalone web apps on a website that will make data visualization easy. These applications made through R Shiny can seamlessly display R objects such as tables and plots.

Let us look at some of the features of R Shiny:

  • Build web applications with fewer lines of code, without JavaScript.
  • These applications are live and are accessible to users like spreadsheets. The outputs may alter in real-time if the users change the input.
  • Developers with little knowledge of web tools can also build apps using R Shiny.
  • You get in-built widgets to display tables, outputs of R objects and plots.
  • You can add live visualizations and reports to the web application using this package.
  • The user interfaces can be coded in R or can be prepared using HTML, CSS or JavaScript.
  • The default user interface is built using Bootstrap.
  • It comes with a WebSocket package that enables fast communication between the web server and R.

Read: Decision Tree in R

Components of an R Shiny app

A Shiny app has two primary components – a user interface object and a server function. These are the arguments passed on to the shinyApp method. This method creates an application object using the arguments.

Learn data science from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Also read: KNN Algorithm in R

Let us understand the basic parts of an R Shiny app in detail:

User interface function

This function defines the appearance of the web application. It makes the application interactive by obtaining input from the user and displaying it on the screen. HTML and CSS tags can be used for making the application look better. So, while building the ui.R file you create an HTML file with R functions.

If you type fluidPage() in the R console, you will see that the method returns a tag <div class=”container-fluid”></div>.    

The different input functions are:

  • selectInput() – This method is used for creating a dropdown HTML that has various choices to select.
  • numericInput() – This method creates an input area for writing text or numbers. 
  • radioButtons() – This provides radio buttons for the user to select an input.

Our learners also read: Top Python Free Courses

Layout methods

The various layout features available in Bootstrap are implemented by R Shiny. The components are:

Panels

These are methods that group elements together into a single panel. These include:

  • absolutePanel()
  • inputPanel()
  • conditionalPanel()
  • headerPanel()
  • fixedPanel()

Explore our Popular Data Science Online Certifications

Layout functions

These organize the panels for a particular layout. These include:

  • fluidRow()
  • verticalLayout()        
  • flowLayout()
  • splitLayout()
  • sidebarLayout()

Output methods

These methods are used for displaying R output components images, tables and plots. They are:

  • tableOutput() –  This method is used for displaying an R table
  • plotOutput() – This method is used for displaying an R plot object

Read our popular Data Science Articles

Server function

After you have created the appearance of the application and the ways to take input values from the user, it is time to set up the server. The server functions help you to write the server-side code for the Shiny app. You can create functions that map the user inputs to the corresponding outputs. This function is called by the web browser when the application is loaded.

It takes an input and output parameter, and return values are ignored. An optional session parameter is also taken by this method.

Top Data Science Skills You Should Learn

R Shiny tutorial: How to get started with R Shiny?

Steps to start working with the R Shiny package are as follows:

  • Go to the R console and type in the command – install.packages(“shiny”)
  • The package comes with 11 built-in application examples for you to understand how Shiny works

You can start with the Hello Shiny example to understand the basic structure. Type this code to run Hello Shiny:

library(shiny)

runExample(“01_hello”) 

The steps to create a new Shiny app are:

  • Open RStudio and go to the File option
  • Select New Project in a directory and click on the “Shiny Web” Application
  • You will get a histogram and a slider to test the changes in output with respect to the input
  • You will get two scripts ui.R and server.R for coding and customizing the application

Tips for Shiny app development

  • Test the app in the browser to see how it looks before sending it for production
  • Run the entire script while debugging the app
  • Be careful about common error such as commas

upGrad’s Exclusive Data Science Webinar for you –

How upGrad helps for your Data Science Career?

 

Conclusion

If you are curious to learn about data science, check out our Executive PG Program in Data Science which is created for working professionals and offers 10+ case studies & projects, practical hands-on workshops, mentorship with industry experts, 1-on-1 with industry mentors, 400+ hours of learning and job assistance with top firms.

The best part of Shiny is that you do not have to know HTML, CSS or JavaScript for using it. Moreover, you can build applications and deploy them on the free version of shinyapps.io. Keep this R Shiny tutorial handy while getting started.

 

Profile

Rohit Sharma

Blog Author
Rohit Sharma is the Program Director for the UpGrad-IIIT Bangalore, PG Diploma Data Analytics Program.

Frequently Asked Questions (FAQs)

1What are the benefits of R Shiny?

Every data scientist needs to take the help of certain tools for bringing out the insights from data in front of the general public. Shiny is a package available in R for developing interactive web applications. You get plenty of options to communicate your results through texts, tables, visualizations, or interactive charts. If you know R programming, you can easily develop an app as Shiny is pretty easy to use. There are built-in capabilities to easily share your work with friends and colleagues. The design of the Shiny app is pretty amazing. Even if you are looking at the default display, you will find it pretty intuitive and elegant.

2How is Shiny found to be different from the traditional applications?

Let us understand this better with the help of an example of a weather application. Whenever the user reloads the page or even changes a small input on the page, the app will have to update the entire page with the help of JS. This will add plenty of load to the server-side in order to process the update.

On the other hand, Shiny will isolate or reload the app elements that reduce server load. The structure will play a very important role in understanding as well as debugging the code. It is found that scrolling through the web applications is a bit difficult with Shiny apps as compared to the traditional applications.

3Is R Shiny hard to learn?

The Shiny framework is a package available in R that is useful for building interactive web applications. The package is wonderful as it allows you to create highly effective visualizations and reports based on the available datasets. Other than using the Shiny elements, you can also use the HTML elements to customize the application content.

Even though Shiny is a pretty powerful tool, you will find it pretty easy to learn if you are aware of programming in R. It is highly recommended to learn R Shiny if you are thinking about adding something creative to your portfolio.

Explore Free Courses

Suggested Blogs

17 Must Read Pandas Interview Questions &amp; Answers [For Freshers &#038; Experienced]
50143
Pandas is a BSD-licensed and open-source Python library offering high-performance, easy-to-use data structures, and data analysis tools. Python with P
Read More

by Rohit Sharma

04 Oct 2023

13 Interesting Data Structure Project Ideas and Topics For Beginners [2023]
223211
In the world of computer science, data structure refers to the format that contains a collection of data values, their relationships, and the function
Read More

by Rohit Sharma

03 Oct 2023

How To Remove Excel Duplicate: Deleting Duplicates in Excel
1324
Ever wondered how to tackle the pesky issue of duplicate data in Microsoft Excel? Well, you’re not alone! Excel has become a powerhouse tool, es
Read More

by Keerthi Shivakumar

26 Sep 2023

Python Free Online Course with Certification [2023]
122163
Summary: In this Article, you will learn about python free online course with certification. Programming with Python: Introduction for Beginners Lea
Read More

by Rohit Sharma

20 Sep 2023

Information Retrieval System Explained: Types, Comparison &amp; Components
52896
An information retrieval (IR) system is a set of algorithms that facilitate the relevance of displayed documents to searched queries. In simple words,
Read More

by Rohit Sharma

19 Sep 2023

40 Scripting Interview Questions &#038; Answers [For Freshers &#038; Experienced]
13600
For those of you who use any of the major operating systems regularly, you will be interacting with one of the two most critical components of an oper
Read More

by Rohit Sharma

17 Sep 2023

Best Capstone Project Ideas &amp; Topics in 2023
2548
Capstone projects have become a cornerstone of modern education, offering students a unique opportunity to bridge the gap between academic learning an
Read More

by Rohit Sharma

15 Sep 2023

4 Types of Data: Nominal, Ordinal, Discrete, Continuous
295266
Summary: In this Article, you will learn about 4 Types of Data Qualitative Data Type Nominal Ordinal Quantitative Data Type Discrete Continuous R
Read More

by Rohit Sharma

14 Sep 2023

Data Science Course Eligibility Criteria: Syllabus, Skills &#038; Subjects
46213
Summary: In this article, you will learn in detail about Course Eligibility Demand Who is Eligible? Curriculum Subjects & Skills The Science Beh
Read More

by Rohit Sharma

14 Sep 2023

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon