Mohamed Rizwan
27/09/2019
library(datasets)
library(shiny)
ui = fluidPage(
titlePanel("stopping distance of cars"),
sidebarLayout(
sidebarPanel(
h4("choose the speed of the car"),
sliderInput("speed",label="speed",min = min(cars$speed),max =max(cars$speed),5,1)
),
mainPanel(
plotOutput("Plot1"),
h4("Distance to stop"),
verbatimTextOutput("Pred1")
)
)
)
server = function(input, output) {
fit <- lm(dist~speed, cars)
Pred1 <- reactive({
speed <- input$speed
predict(fit, newdata=data.frame(speed=input$speed))
})
output$Plot1 <- renderPlot({
speed <- input$speed
plot(cars$speed,cars$dist, xlab="speed",ylab="distance",bty="n", pch=20)
abline(fit,col="red",lwd=1)
points(speed,Pred1(), col='blue',pch= 16,cex=3)
})
output$Pred1 <- renderText({
Pred1()
})
}