Skip to content

Instantly share code, notes, and snippets.

@wch
Created November 6, 2012 06:51
Show Gist options
  • Select an option

  • Save wch/4023122 to your computer and use it in GitHub Desktop.

Select an option

Save wch/4023122 to your computer and use it in GitHub Desktop.
Scatter plot with model fit lines
library(shiny)
shinyServer(function(input, output) {
output$main_plot <- reactivePlot(function() {
plot(x = faithful$eruptions, y = faithful$waiting,
xlab = "Eruption duration (minutes)",
ylab = "Waiting to next eruption (minutes)",
main = "Eruptions of Old Faithful geyser")
if (input$show_model == "Linear") {
abline(lm(waiting ~ eruptions, data = faithful), col = "blue")
} else if (input$show_model == "LOWESS") {
lines(lowess(faithful$eruptions, faithful$waiting), col = "blue")
}
})
})
library(shiny)
shinyUI(bootstrapPage(
selectInput(inputId = "show_model",
label = "Show prediction from model:",
choices = c("None", "Linear", "LOWESS")),
plotOutput(outputId = "main_plot")
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment