ShinyApp-Presentation

David Asare Kumi
December 24, 2018

Introduction

This 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 data used for this analysis is the airquality dataset where we establish the relationship and predict the response variable Solar Radiation (Solar.R) based on the predictor variable Temperature (Temp).

Below are the links to the analysis done;

ui.R

library(shiny)
shinyUI(fluidPage(
  titlePanel("Predict Solar Radiation from Temperature"),

  sidebarLayout(
    sidebarPanel(
      h4("This is a scatterplot of Temp and Solar.R"),
      h4("The plot reveals a positive relationship between Temp and Solar.R"),
      h4("Use Checkboxes and Submit Button to determine Predictions"),
       sliderInput("sliderTEMP","What is the surface TEMP?",50,100,value=65),
       checkboxInput("showModel1","Show/Hide Model 1",value=TRUE),
       checkboxInput("showModel2","Show/Hide Model 2",value=TRUE),
      submitButton("Submit")
    ),

    mainPanel(
       plotOutput("plot1"),
       h3("Predicted Solar Radiation from Model1:"),
       textOutput("pred1"),
       h3("Predicted Solar Radiation from Model2:"),
       textOutput("pred2")
    )
  )
))

<!–html_preserve–>

Predict Solar Radiation from Temperature

This is a scatterplot of Temp and Solar.R

The plot reveals a positive relationship between Temp and Solar.R

Use Checkboxes and Submit Button to determine Predictions

Predicted Solar Radiation from Model1:

Predicted Solar Radiation from Model2:

<!–/html_preserve–>

server.R

library(shiny)
shinyServer(function(input, output) {
  airquality$Tempsp <-ifelse(airquality$Temp - 65 > 0,airquality$Temp - 65,0)
  model1 <-lm(Solar.R~Temp,data=airquality)
  model2 <-lm(Solar.R~Tempsp+Temp,data=airquality)

  model1pred <-reactive({
    TempInput <-input$sliderTEMP
    predict(model1,newdata=data.frame(Temp=TempInput))
  })
  model2pred <-reactive({
    TempInput <-input$sliderTEMP
    predict(model2,newdata=data.frame(Temp=TempInput,Tempsp=ifelse(TempInput-65>0,TempInput-65,0)))
  })

  output$plot1 <- renderPlot({
    TempInput <-input$sliderTEMP
    plot(airquality$Temp,airquality$Solar.R,xlab="Temp",ylab="Solar.R",bty="n",pch=16,xlim=c(50,100),
         ylim=c(5,350))
    if(input$showModel1){
      abline(model1,col="red",lwd=2)
    }
    if(input$showModel2){
      model2lines <-predict(model2,newdata=data.frame(Temp=50:100,Tempsp=ifelse(50:100 - 65>0,
                                                                                50:100-65,0)))

      lines(50:100,model2lines,col="blue",lwd=2)
    }
    legend(85,50,c("Model 1 Prediction","Model 2 Prediction"),pch=16,col=c("red","blue"),bty="n",cex=1.2)

    points(TempInput,model1pred(),col="red",pch=16,cex=2)
    points(TempInput,model2pred(),col="blue",pch=16,cex=2)
  })
  output$pred1 <-renderText({
    model1pred()
  })
  output$pred2 <-renderText({
    model2pred()
  })
  })

Conclusion

The codes provided above are the codes that produced the shinyApp which is published on the shiny website stated in the introduction slide above.

The checkboxes and the submit button in the shinyApp are the widgets used in determining the predictions.

THANKS!!!