- "What temperature is it Mom?"
- "70 degrees"
- "Is it windy?"
- "No idea."
- "That's ok, I have this handy app that Amanda made!"
January 23, 2016
library(shiny)
shinyUI(fluidPage(
titlePanel("Predict Wind Speed from Temperature"),
sidebarLayout(
sidebarPanel(
numericInput("TempInput",
"What is the temperature in degrees F?",
70, min = 50, max = 100, step = 1),
checkboxInput("showModel", "Show Model", value = TRUE),
checkboxInput("showInt", "Show Prediction", value = TRUE),
submitButton("Go!")
),
mainPanel(
plotOutput("plot1"),
h3("Predicted Wind:"),
textOutput("pred")
)
)
))
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
lm <- lm(Wind ~ Temp, data = airquality)
pred <- reactive({
TempIn <- input$TempInput
predict(lm, newdata = data.frame(Temp = TempIn))
})
output$plot1 <- renderPlot({
TempIn <- input$TempInput
g <- ggplot(data = airquality, aes(x = Temp, y = Wind)) +
geom_point()
print(g)
if(input$showModel){
g <- g + geom_smooth(method = "lm")
print(g)
}
if(input$showInt){
g <- g + geom_vline(xintercept = input$TempInput,
color="red")
print(g)
}
output$pred <- renderText({
pred()
})
})
})
You can check out my app at https://asalvesen.shinyapps.io/Data_Products/ and supporting documentation at https://github.com/asalvesen/Data-Products.