July 8, 2017

Price Predictor for Your Diamonds

This "Price Predictor for Your Diamonds" is a predictor tool generated for the week 4 assignment of the coursera project. It alllows you to conviniently have some ideas about what price you should pay for your diamonds if you are interested to know.

Steps were used to create the App

  1. Create an Account in Shinyapps.io
  2. Run the setAccountInfor
  3. library(rsconnect)
  4. library(shiny)

ui.R

library(shiny); library(ggplot2); dataset <- diamonds

fluidPage(

titlePanel("Price Predictor for your Diamonds"),

sidebarPanel(

sliderInput('slidercarat', 'Your Carat Value', min=min(dataset$carat),                   max=max(dataset$carat), value=0.2, step=0.01),
checkboxInput("showModel1", "Show/Hide Model 1", value = TRUE),
submitButton("Submit")),

mainPanel( plotOutput("plot1"), h3("Predicted Price from Model 1:"), textOutput("pred1") ))

server.R

library(shiny) library(ggplot2) dataset <- diamonds

function(input, output) { model1 <- lm(price ~ carat, data = dataset) model1pred <- reactive({ caratInput <- input$slidercarat predict(model1, newdata = data.frame(carat = caratInput)) })

output\(plot1 <- renderPlot({ caratInput <- input\)slidercarat plot(dataset\(carat, dataset\)price, xlab = "carat", ylab = "Price", pch=16, xlim = c(0, 6), ylim = c(200, 19000)) if(input$showModel1){ abline(model1, col="red", lwd=2) }

legend(25,250, "Model 1 Prediction", pch=16, col = "red", bty="n", cex=1.2) points(caratInput, model1pred(), col="red", pch=16, cex=2) })

output$pred1 <- renderText({ model1pred() }) }

Link to the App