Developing Data Products Project 4: Reproducible Pitch Production

ealbert

1/27/2022

Instructions

Your Reproducible Pitch Presentation

OK, you’ve made your shiny app, now it’s time to make your pitch. You get 5 slides (inclusive of the title slide) to pitch a your app. You’re going to create a web page using Slidify or Rstudio Presenter with an html5 slide deck.

Here’s what you need

  1. 5 slides to pitch our idea done in Slidify or Rstudio Presenter

  2. Your presentation pushed to github or Rpubs

  3. A link to your github or Rpubs presentation pasted into the provided text box

Your presentation must satisfy the following

  1. It must be done in Slidify or Rstudio Presenter

  2. It must be 5 pages

  3. It must be hosted on github or Rpubs

  4. It must contained some embedded R code that gets run when slidifying the document

Ui.R Codes used in the Shiny app interactive webpage

library(shiny)
shinyUI(fluidPage(
  titlePanel("mtcars Miles per gallon Data"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Frequency Ranges",
                  min = 5,
                  max = 50,
                  value = 12),
      checkboxInput("showmeanstd", 'Show/hide the mean value', value = TRUE),
      sliderInput("sliderMPG",
                  "Miles per Gallon per frequency",
                  min = 5,
                  max = 50,
                  value = 20),
      checkboxInput("showmodel", 'Show Linear Model', value = TRUE)
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Plot",
                 fluidRow(
                   column(8, plotOutput("histPlot")),
                   column(8,  h3("Horsepower Prediction"), textOutput("pred")),
                   column(8, plotOutput("lmplot"))
                 ))
      ))
  )
))

Sever.R Codes used in the Shiny app interactive webpage.

library(shiny)
shinyServer(function(input, output) {
  output$histPlot <- renderPlot({
    x    <- mtcars$mpg  
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    hist(x, breaks = bins, col = 'green', border = 'black', xlab = "MPG", main = "MPG Dataset")
    if (input$showmeanstd){
      abline(v = mean(x), col = "red", lwd = 2)
      abline(v = c(mean(x) - sd(x), mean(x) + sd(x)), col = "orange", lwd = 3, lty = 2)
    }
  })
  model_lm <- lm(hp~mpg, data = mtcars)
  model_lm_pred <- reactive({
    mpgInput <- input$sliderMPG
    predict(model_lm, newdata = data.frame(mpg = mpgInput))
  })
  output$lmplot <- renderPlot({
    mpgInput <- input$sliderMPG
    plot(mtcars$mpg, mtcars$hp, xlab = "Miles Per Gallon", ylab = "Horsepower", main = "MPG Prediction Model")
    if (input$showmodel){
      abline(model_lm, col = "red", lwd = 2)}
    points(mpgInput, model_lm_pred(), col = "blue", pch = 16, cex = 2)
  })
  output$pred <- renderText({
    model_lm_pred()})
})