5/20/2020

Shiny App : Graphs and Linear Regression Model Summary

Shiny applications have two components: - a user-interface definition (UI) file called ui.R - a server script file called server.R

Objective - Develop a Shiny app and deploy on Rstudio’s server. - Prepare R presentation demonstrating the app.

An overview of the dataset used: mtcars (11 var,32 obs)

                   mpg cyl disp  hp drat    wt  qsec vs am gear carb
Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2

For ui.R

We first start with attaching the libraries: shiny and ggplot2

  1. For Page layout: Inside fluidPage I created 3 fluidRows with diffrent width columns.

  2. For Inputs: 4 select inputs (for variables & geom) & 3 checkbox input (for labels)

  3. For outputs: display 3 outputs

  • XY plot, residual vs fitted values plot & Text: Fit summary

Variable selection choices are:

 [1] "mpg"  "cyl"  "disp" "hp"   "drat" "wt"   "qsec" "vs"   "am"   "gear"
[11] "carb"

For server.R:

1.In order to display different geom in ggplot outplot: I made a reactive plot_geom with switching options:

  • geom_(…): point, smooth, fit, jitter, violin, box

  • Then, I renderplot with ggplot having input chocies of variables, factor/color & plot_geom

2.For output Fit summary renderPrint the linear regression formula as: - Fit<- lm(y ~ x + a) # “a” being the factor var of choice - summary(Fit)

3.For plotFit renderplot for residual vs fitted values of linear regression model that we have created.

Final Shiny App