Developing Data Product - Week 4 Assignment

Gagan J H

06 November 2020

Coursera Reproducible Pitch

This is done a part of data science course, about developing data products for week 4, offered on coursera by John Hopkins University. To fufil the course assignment I have developed a Shiny app and deployed it on the shiny server. The link is . The code can be found at This is a task for the data science coursera course about developing data products for week 4. As part of this, I have created a shiny app and deployed it on the shiny server. The link is https://gagan081998.shinyapps.io/Shinyapp/. The code can be found at https://github.com/Gagan081998/Developing_data_products/tree/main/Shinyapp

Overview

The shiny app plots graph against horsepower(hp) for different variables from the auto-mpg dataset.

cars <- read.csv('auto-mpg.csv')
head(cars)
##   mpg cylinders displacement horsepower weight acceleration model.year origin
## 1  18         8          307        130   3504         12.0         70      1
## 2  15         8          350        165   3693         11.5         70      1
## 3  18         8          318        150   3436         11.0         70      1
## 4  16         8          304        150   3433         12.0         70      1
## 5  17         8          302        140   3449         10.5         70      1
## 6  15         8          429        198   4341         10.0         70      1
##                    car.name
## 1 chevrolet chevelle malibu
## 2         buick skylark 320
## 3        plymouth satellite
## 4             amc rebel sst
## 5               ford torino
## 6          ford galaxie 500

UI Code

library(shiny)

shinyUI(
  navbarPage("Technical Specification Analysis",
             tabPanel("Analysis",
                      fluidPage(
                        titlePanel("The relationship between various factors and acceleration"),
                        sidebarLayout(
                          sidebarPanel(
                            selectInput("variable", "Variable:",
                                        c("MPG" = "mpg",
                                          "Number of cylinders" = "cylinders",
                                          "Displacement (cu.in.)" = "displacement",
                                          "Weight (lb/1000)" = "weight",
                                          "acceleration (sec)" = "acceleration"
                                        ))
                          ),
                          
                          mainPanel(
                            h3(textOutput("caption")),
                            
                            tabsetPanel(type = "tabs", 
                                        tabPanel("Plot", plotOutput("carsBP"))
                            )
                          )
                        )
                      )
             ),
             tabPanel("About the Data Set",
                      
                      h3("Kaggle autompg-data"),
                      helpText("We have used the 'Auto-MPG Data' datasetto understand how weight (wt), horsepower (hp), and number of cylinders (cyl) affects the acceleration of a car.",
                               "The dataset contains the technical specifications of the various vehicles. The dataset is downloaded from the UCI Machine Learning Repository."),
                      
                      h3("Important"),
                      p("A data frame with 398 observations on 6 variables."),
                      
                      a(" https://archive.ics.uci.edu/ml/datasets/auto+mpg")
             ),
             tabPanel("More Data Detail",
                      h2("Auto-mpg dataset"),
                      hr(),
                      h3("Description"),
                      helpText("The data is technical spec of cars.",
                      "The dataset is downloaded from UCI Machine Learning Repository"),
                              
                      h3("Format"),
                      p("A data frame with 398 observations on 6 variables."),
                      
                      p("  [, 1]   mpg         Miles/(US) gallon"),
                      p("  [, 2]     cylinder    Number of cylinders"),
                      p("  [, 3]     displacement    Displacement (cu.in.)"),
                      p("  [, 4]     horsepower  Gross horsepower"),
                      p("  [, 5]     weight  Weight(lbs)"),
                      p("  [, 6]   acceleration acceleration(sec)"),
                      h3("Source"),
                      
                      p("This dataset was taken from the StatLib library which is",
                        "maintained at Carnegie Mellon University. The dataset was",
                        "used in the 1983 American Statistical Association Exposition.")
             ),
             tabPanel("Go back to my Github repository",
                      a("https://github.com/Gagan081998/Developing_data_products/tree/main/Shinyapp"),
                      hr(),
                      h4("I hope you like the Shiny App"),
                      h4("The name of the repository is Developing Data Products/Shinyapp")
             )
  )
)

Server Code

library(shiny)

cars <- read.csv('auto-mpg.csv')

shinyServer(function(input,output)
  {
  formulaText <- reactive({
    paste("horsepower ~ ",input$variable)
  })
  
  formulaTextPoint <- reactive({
    paste("horsepower ~", "as.integer(",input$variable,")")
  })
  
  
  output$cap <- renderText({
    formulaText()
  })
  
  output$carsBP <-renderPlot({
   plot(as.formula(formulaText()),data = cars, outline = input$outliers)
  })
  
  
})