Objective of the Project
- To create a Shiny application and deploy it on Rstudio’s servers
- Use Slidify or Rstudio Presenter to prepare a reproducible pitch presentation about your application
2023-11-16
Objective of the Project
Description The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).
Format:
A data frame with 32 observations on 11 (numeric) variables.
The dataset mtcars has been used in this project. The Shiny application created with this data will show the Histogram for continuous variables and Bar chart for discrete variables. After creating the Shiny application, it has been deployed on Rstudio’s servers. The two code files server.R and ui.R are pushed to github Rstudio presenter has been used to prepare a reproducible pitch presentation about our application Github Repository Link for ui.R and server.R files https://github.com/DannyMutd/DDPweek4/tree/main
library(shiny) shinyUI( navbarPage(“Shiny Application”, tabPanel(“Analysis”, fluidPage( titlePanel(“mtcars Dataset”), sidebarLayout( sidebarPanel( radioButtons(“var”, “Select a variable of mtcars dataset:”, list(“mpg”, “cyl”, “disp”, “hp”, “drat”, “wt”, “qsec”, “vs”, “am”, “gear”, “carb”)), sliderInput(“bins”, “Number of bins for histogram:”, min = 1, max = 50, value = 30) ), mainPanel( plotOutput(“distPlot”), plotOutput(“distplot”) ) ) ) ), tabPanel(“About the Data Set”, h2(“Course Project: Shiny Application and Reproducible Pitch”), h3(“Data Description”), helpText(“The dataset ‘mtcars’ was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models)”), p(“This dataset consits of 32 observations on 11 numeric variables”),
h3("Data Format"),
h6("1. mpg: Miles/(US) gallon"),
h6("2. cyl: Number of cylinders"),
h6("3. disp: Displacement (cu.in.)"),
h6("4. hp: Gross horsepower"),
h6("5. drat: Rear axle ratio"),
h6("6. wt: Weight (1000 lbs)"),
h6("7. qsec: 1/4 mile time"),
h6("8. vs: Engine (0 = V-shaped, 1 = straight)"),
h6("9. am: Transmission (0 = automatic, 1 = manual)"),
h6("10. gear: Number of forward gears"),
h3("Data Source"),
p("https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/mtcars")
),
tabPanel("Project Instruction",
h2("Developing Data Products - Week4 Assignment: Shiny Application and Reproducible Pitch"),
h3("This assignment has two parts"),
h5("1. Shiny Application"),
h5("2. Reproducible Pitch Presentation"),
h5("First you will create a Shiny application and deploy it on Rstudio's servers. Second, you will use Slidify or Rstudio Presenter to prepare a reproducible pitch presentation about your application")
)
)
)
This is the server logic of a Shiny web application. You can run the application by clicking ‘Run App’ above.# Find out more about building applications with Shiny here: http://shiny.rstudio.com/
#SERVER.R
library(shiny) #writing server function shinyServer(function(input, output) { #referring output distPlot in ui.r as output\(distPlot output\)distPlot <- renderPlot({ #referring input ‘var’ in ui.r as input$var
if(input$var=='mpg'){
i<-1
}
if(input$var=='cyl'){
i<-2
}
if(input$var=='disp'){
i<-3
}
if(input$var== 'hp'){
i<-4
}
if(input$var=='drat'){
i<-5
}
if(input$var=='wt'){
i<-6
}
if(input$var=='qsec'){
i<-7
}
if(input$var=='vs'){
i<-8
}
if(input$var=='am'){
i<-9
}
if(input$var=='gear'){
i<-10
}
if(input$var=='carb'){
i<-11
}
if(i %in% c(1, 3:7)){
x <- mtcars[,i]
x0 <- mtcars[i]
header = paste("Histogram of a Continuous Variable:", names(x0))
#referring input bins in ui.r as input$bins
bins <- seq(min(x), max(x), length.out = input$bins + 1)
#producing histogram as output
hist(x, breaks = bins, col = 'darkblue', border = 'white', xlab = names(x0), ylab='Frequency', main = header)
}
else {
x2 <- mtcars[i]
header = paste("Bar Chart of a Categorical Variable:", names(x2))
barplot(table(x2), main = header, col="darkgreen", xlab = names(x2), ylab='Frequency')
}
}) })