Files
shiny/examples/03_distributions/server.R
2012-07-19 14:26:01 -07:00

40 lines
907 B
R

library(shiny)
server(function(input, output) {
data <- reactive(function() {
# If the Animate checkbox is checked, then we want to re-calculate this
# reactive function 1 second from now
if (input$animate)
invalidateLater(1000)
# Choose a distribution function
dist <- switch(input$dist,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
# Generate n values from the distribution function
dist(as.integer(input$n))
})
output$plot1 <- reactivePlot(function() {
dist <- input$dist
n <- input$n
hist(data(),
main=paste('r', dist, '(', n, ')', sep=''))
})
output$table1 <- reactiveTable(function() {
data.frame(x=data())
})
output$summary1 <- reactiveText(function() {
summary(data())
})
})