Coursera Developing Data Products: Shiny Application and Reproducible Pitch

Christine Arsenault
July 1, 2018

Project Description:

This peer assessed assignment has two parts. 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.

The source code for this project (ui.R and server.R files) are available on GitHub at: https://github.com/CArsenault/DevelopingDataProducts_Wk4Project

The application has been deployed to: https://ctarsenault.shinyapps.io/shinydiamonds/

The intended result of this project is for a user to have the ability to predict the cost of a diamond, in US dollars, using the carat weight as a predictor.

The dataset selected for this project is the diamonds dataset included with ggplot2. The diamonds data frame consists of 53,940 rows with the following 10 variables:

  • price: in US dollars ($326–$18,823)

  • carat: weight of the diamond (0.2–5.01)

  • cut: quality rated as Fair, Good, Very Good, Premium, Ideal

  • color: from J (worst) to D (best)

  • clarity: a measurement of how clear the diamond is (I1 (worst), SI2, SI1, VS2, VS1, VVS2, VVS1, IF (best))

  • x: length in mm (0–10.74)

  • y: width in mm (0–58.9)

  • z: depth in mm (0–31.8)

  • depth: total depth percentage = z / mean(x, y) = 2 * z / (x + y) (43–79)

  • table: width of top of diamond relative to widest point (43–95)

UI Slide

library(shiny)

shinyUI(
        pageWithSidebar(
                #Predict the cost of a diamond
                headerPanel = ("Using Carat Weight to Predict Diamond Cost"),

                sidebarPanel(
                        numericInput('carat', 'Enter Carat Weight', 0.2, min = .02, max = 5.0, step = 0.01),
                        submitButton('Submit')
                ),
                mainPanel(
                        h3('Prediction Results'),
                        h4('Selected carat weight:'),
                        verbatimTextOutput('inputValue'),
                        h4('Predicted Cost (in $US)'),
                        verbatimTextOutput('prediction')

                )
        )
)

<!–html_preserve–>

Using Carat Weight to Predict Diamond Cost

Prediction Results

Selected carat weight:


Predicted Cost (in $US)


<!–/html_preserve–>

Server Slide

library(shiny)
library(UsingR)
data(diamond)

fit= lm(price ~ carat, data = diamond)
slope<-coef(fit)[2]
names(slope)<- "US$ Dollars"

Price <- function(carat) {0.77*(carat*slope + coef(fit)[1])}

shinyServer(
        function(input, output) {
                output$inputValue <- renderPrint({input$carat})
                output$prediction <- renderPrint({Price(input$carat)})
        }
)