R Shiny App — Creating an App on R shiny and sharing with Shinyapps.io
By: Ruchi Deshpande
Tags: R, Clustering, Web Dashboard, Editors Pick, R Shiny

Photo by DESIGNECOLOGIST on Unsplash

R offers some very intuitive graphs and all those who have used R are quite familiar with R shiny as well. R shiny enables one to create interactive dashboards whereby we can make the full use of R plotting capabilities along with reactive graphs and tables. This is particularly useful for analysts, researchers who would like to have a BI tool like environment along with the statistical computational capabilities of R packages.

In this blog, I have demonstrated how we can create interactive dashboard using R Shiny and how to share your app on Shinyapp.io. I have used a freely available dataset from Data Flair(https://data-flair.training/blogs/data-science-project-ideas/). This data is for Customer Segmentation using K-means clustering algorithm. I have not paid much attention to the accuracy of the model here, as the sole purpose of this blog is to demonstrate R shiny apps. I have created menus and sub-menus in the dashboard which clearly highlight the steps involved in clustering this data.

Since, R Shiny gives the power to make your dashboards interactive, I have given the user to choose the cluster number through a slider input. The number of clusters changes the graph accordingly and one can also view the cluster statistics change with it. I have used Dunn Index as a metric to evaluate the algorithm.

Although, the number of clusters can be determined by a number of statistical techniques(which again are a part of my solution) and domain knowledge, I thought it will be fun for the user to play with the graph a bit without worrying about the code.

You can view the complete dashboard here : https://ruchideshpande.shinyapps.io/csapp/

My code has both the UI and Server codes in one R file called app.R. Libraries and data can also be loaded in the same file. Here, other than the regular libraries for clustering, library shiny and library shinydashboard is loaded, these two libraries being mandatory for R shiny dashboard.

The UI section lays out the look and feel of your dashboard. The dashboard body along with the header, menus and sub-menus are defined here.

The Server part of the code is a bit tricky , mainly because all output tables, graphs are nested in the shinyServer function to make the output reactive. My advice would be to be careful with the brackets, and look out for appropriate render functions, as writing the code within the render functions is similar to writing any R code.

Creating R shiny dashboards is easy once you are familiar with the shiny functions as the code for building any model is same as writing the code in R. I hope that this blog will be a good starting point for anyone wishing to start their first R shiny project.

I have purposefully refrained from sharing steps to create the app and sharing it because https://shiny.rstudio.com/ has a very detailed documentation and videos for beginners. In case any one of you reading my blog have any questions how to go about it, I will be happy to help.

Please feel free to share your comments, suggestions and feedback here!!