the results of my statistical models as web applications. After doing some
research over the internet I’ve come across – ShinyR – a new package
from RStudio which can be used to develop interactive web applications with R.
Before going into how to build web apps using R, let me give you some overview
- Can build interactive web applications which can load the data dynamically.
- Pre-Built output widgets for displaying plots, tables interactively are available.
- Works in any R environment.
- Shiny Apps can be hosted locally/on self-hosted Shiny Server/Rstudio-hosted Shiny Server – in today’s post we will see hosting locally.
Building a shiny App
Shiny application have two components: a user-interface definition and server script,
and any additional data, scripts, or other resources required to support the
UI script (ui.R): In this script we define the UI layout of the webpage. We can make
use of inbuilt UI controls/widgets for displaying output and for creating UI layout..
Server Script (server.R): In this script, the actual business logic/ code for statistical
models, plotting the output is defined. It accepts inputs from UI layer and compute
outputs send back the response to the UI layer. The basic task of a Shiny server
script is to define the relationship between inputs and outputs.
Understanding UI.R script:
library(shiny) #load shiny package
ds = read.csv(“inputdata.csv”) #load data
x = names(ds) # Define UI for application that plots distributions
# Application title
headerPanel(“Demo Shiny Application”),
#sidebar panel to the left side of the page for input controls, slider & dropdown
sliderInput(‘Year’, ‘Year’, min=2010, max=2012,
value=min(2010,2012), step=1, round=0),
selectInput(‘select’, ‘Select Criteria’, c(x,x,x,x,x,x))
#main panel for displaying outputs, Histograms, summary
Notice in particular, in the above code sidebarPanel and mainPanel functions
are called with two arguments – corresponding to the two inputs and
two outputs displayed.
In the above image we can see the layout which contains a slider with year range,
where based on the year selection the dataset will be taken into consideration.
Dropdownlist containing varaibles, placeholder to display the graphs, table to
display the summaries of the models.
Deploying the application:
- ** Create a local- self-hosted Shiny Server on Linux platform, here.
- ** Host on the R-Studio’s Shiny server, explained here
- ** Upload the Server.R & UI.R files to the Gist.Github.com website.
- ** Uploading the files gives you an ID – in my case – I got “8942533”
- ** After finishing upload, open R and run the below code:
- The model will be shown as web application will be displayed
the browser with inputs for selection & outputs to display.