Course Project: Shiny Application and Reproducible Pitch

Assefa Melorie

7/27/2020

Overview

The \(airquality\) data sets available in R is used for this project. The data set has six variables in which we focused on the effects of temperature on Ozone values.
Two models have been used for the data prediction. For details of the project please use README.md file as a reference.
This project have two parts:
1. Shiny Application
2. Reproducible Pitch Presentation

Shiny Application

ui.R code

library(shiny)
shinyUI(fluidPage(
    titlePanel("Estimating Ozone from Temperature"),
    sidebarLayout(
        sidebarPanel(
            sliderInput("SliderTemp", "What is the Temperature?",56,97, value = 74),
            checkboxInput("showModel1", "Show/Hide Model 1", value = TRUE),
            checkboxInput("showModel2", "Show/Hide Model 2", value = TRUE)
        ),
        mainPanel(
            plotOutput("plot1"),
            h4("Predicted Ozone from Model 1:"),
            textOutput("pred1"),
            h4("Predicted Ozone from Model 2:"),
            textOutput("pred2"),
            h3("Note:"),
            textOutput("note")
            
        )
    )
))

…Continued

server.R code

library(shiny)
shinyServer(function(input, output) {
    airquality$Temp1<- ifelse(74 - airquality$Temp > 0, 74 - airquality$Temp, 0)
    fit1<- lm(Ozone ~ Temp, data = airquality)
    fit2<- lm(Ozone ~ Temp1 + Temp, data = airquality)
    
    fit1pred <- reactive({
        TempInput <- input$SliderTemp
        predict(fit1, newdata = data.frame(Temp = TempInput))
    })
    fit2pred<- reactive({
        TempInput <- input$SliderTemp
        predict(fit2, newdata = data.frame(Temp = TempInput,
                               Temp1 = ifelse(74 - TempInput > 0,
                                              74 - TempInput, 0)))
    })
    output$plot1<- renderPlot({
        TempInput <- input$SliderTemp
        
        plot(airquality$Temp, airquality$Ozone, xlab = "Temperature (degrees F)",
             ylab = "Ozone(ppb)", bty = "n", pch = 16, 
             xlim = c(50, 100), ylim = c(0, 170))
        if(input$showModel1){
            abline(fit1, col = "red", lwd = 2)
        }
        if(input$showModel2){
            fit2lines<- predict(fit2, newdata = data.frame(
                Temp = 56:97, Temp1 = ifelse(74 -56:97 > 0, 74 -56:97, 0)
            ))
            lines(56:97, fit2lines, col = "blue", lwd = 2)
        }
        legend(50, 150, c("Model 1 Prediction", "Model 2 Prediction"),
               pch = 16, col = c("red", "blue"), bty = "n", cex = 1.2)
        points(TempInput, fit1pred(), col = "red", pch = 16, cex = 2)
        points(TempInput, fit2pred(), col = "blue", pch = 16, cex = 2)
    })
    output$pred1<- renderText({
        round(fit1pred(), 2)
    })
    output$pred2<- renderText({
        round(fit2pred(), 2)
    })
    output$note <- renderText({
        "Splitting point Temp = 74 is chosen by visual observation of the graph."
    })
    
})

Reproducible Pitch Presentation

-The shiny application is published into shinyapps.io.
https://assefa.shinyapps.io/Course_Project_Shiny_Application/

-The codes for shinyapp (ui.R and server.R) are shown above and the presentation slide is unloaded into Rpubs.
http://rpubs.com/Asse/ReproduciblePitch/