Introduction to R Shiny dashboards

Almas
Analytics Vidhya
Published in
5 min readDec 27, 2019

As the increasing trend of presenting analysis through dashboards at every level ranging from individual scale to the organization level, data scientists usually face issues while selecting the platform for creating dashboards as the most prominent platforms such as Tableau and Power Bi comes with a cost and also a requirement for data to be in a particular format.

At this point comes into the light the most simple and open source way of creating dashboards, i.e. RShiny dashboards.

You can create amazing interactive dashboards using any sort of data imported or created using R programming. The most important thing about Shiny dashboards are that they are simple to create with reusing the templates and moulding the designs by tweaking the codes.

Let us start with the basics of Shiny dashboards and some of its essential features with this discussion mostly based on the type of inputs that can be taken from different widget styles created in sidebar.

Basics

install.packages("shinydashboard")

A dashboard has three parts: a header, a sidebar, and a body.

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
server <- function(input, output) { }
shinyApp(ui, server)

You can also create two different files such as ui.R and app.R and then calling through R console by using shinyApp() function.

Let us create a basic dashboard with taking into account the major elements of a dashboard.

Components

Header

header <- dashboardHeader(title = “Basic Dashboard”)

This statement simply creates a header of the dashboard with title and you can also insert some fonts to make things more interesting.

Sidebar

Here comes a very interesting part of the dashboard UI where you can create different styles of widgets for taking in the inputs or filtering the data.

Radio button Input Widget —

This widget maps each value with an operation in the main body or filtering out the data with help of functions defined in server app.

Note: The interactive part of dashboard that changes on based of these inputs will be explained in the subsequent articles.

sidebar <- dashboardSidebar(
sidebarMenu(
sidebarSearchForm(textId = "searchText",buttonId = "searchButton",
label = "Search..."),
menuItem("List of Data Classification", tabName = "list", icon = icon("list")),
radioButtons("rtype","Choose Categories :",
choiceNames = c('By Sources', 'By Data Types','By Modeling', 'By Processing', 'Data at Rest vs Data in Motion'),
choiceValues = c(1,2,3,4,5))

Search Form —

This is used to search for keywords in the dashboard and is located with a search magnifying glass icon.

sidebarSearchForm(textId = "searchText", buttonId = "searchButton", label = "Search...")

Text Input —

This is used to get the input in text form which can be used in the other functions for manipulation of data or creation of specialised dashboards.

textInput("text", "Let's get your idea !")

Dropdown Menu Input —

Dropdowns are used as widgets where there are many values to be selected from and cannot be displayed as radio buttons.

selectInput("dropdown","Select the type of data sources :",     c("Transactions" = 1,"Interactions" = 2,"Observations" = 3))

Checkbox Input —

When the inputs taken can be multiple values, in that case we definitely need something like check boxes to input the multiple values which can be further used for analysis.

checkboxGroupInput("check","Select the type of databases :",c("Row Major" = 1,"Column Major" = 2,"NOSQL databases" = 3, "Text data" = 4)) 

Slider Input —

When we have to provide the input in the range for a continuous variable such as percentage range.

sliderInput("slide","Percentage of Data Quality :", min = 0, max = 100, value = 80)

Date Range Input —

To filter the data or analyse it in a particular date range, this particular filter might be of great use.

dateRangeInput('date',"Date Range :", start = Sys.Date() - 10, end = Sys.Date() + 10)

Body

This section includes the displaying of data or creation of plots that are the main part of analysis in the dashboards. Here, I have just included a skeleton and we will discuss more about this part in later sections.

body <- dashboardBody(
fluidRow(
infoBox("The actions might be based on the input selected.", icon = icon('charging-station')))
)

R shiny dashboards gives a lot of freedom in the creation of dashboards, we will be kept wondering how to show small information or a specific plot or an image of data itself by dynamically changing the inputs and features in other UI based applications but R working directly on code base and raw data can make these small creations very efficiently and easily.

I am personally a huge fan of R Shiny dashboards and have used it extensively to create tailor made dashboards for my clients and when I observed there are very few resources online about Shinydashboard I thought of doing the honours myself. :)

Below is the official page for Shiny packages and functions which is great to start with –

https://rstudio.github.io/shinydashboard/structure.html

--

--

Almas
Analytics Vidhya

In a process of understanding life more and trying to be less wrong.