Skip to content

Instantly share code, notes, and snippets.

@garrettgman
Created September 23, 2013 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrettgman/6673251 to your computer and use it in GitHub Desktop.
Save garrettgman/6673251 to your computer and use it in GitHub Desktop.
A very simple Shiny App
library(shiny)
shinyServer(function(input, output) {
data <- reactive({
FUN <- switch(input$family,
"Normal" = rnorm,
"Uniform" = runif,
"Exponential" = rexp)
FUN(input$n)
})
output$histogram <- renderPlot({
hist(data(), breaks = input$bins)
})
})
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Interactive Histogram"),
sidebarPanel(
numericInput("n", "Generate this many points",
min = 1, value = 1000),
selectInput("family", "From this family",
choices = c("Normal",
"Uniform",
"Exponential"),
selected = "normal"),
sliderInput("bins", "number of bins",
min = 1, max = 100, value = 50)
),
mainPanel(
plotOutput("histogram")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment