Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Created November 23, 2012 18:52
Show Gist options
  • Save jcheng5/4136824 to your computer and use it in GitHub Desktop.
Save jcheng5/4136824 to your computer and use it in GitHub Desktop.
# global.R
dists <- list(
normal = list(
label = "Normal",
func = rnorm,
inputs = tagList(
sliderInput("mean", "mean: ", min=0, max=400, value=0),
sliderInput("sd", "st. dev.: ", min=0.1, max=20, value=1, step=.1)
),
params = c("mean", "sd")
),
beta = list(
label = "Beta",
func = rbeta,
inputs = tagList(
sliderInput("shape1", "shape1: ", min=0.1, max=10, value=1, step=0.05),
sliderInput("shape2", "shape2: ", min=0.1, max=10, value=1, step=0.05)
),
params = c("shape1", "shape2")
)
)
distChoices <- names(dists)
names(distChoices) <- sapply(dists, function(x) {x$label})
# ui.R
selectInput("popDist", "Population", distChoices),
lapply(names(dists), function(name) {
conditionalPanel(condition = sprintf("input.popDist == '%s'", name),
dists[[name]]$inputs)
})
# server.R
params <- reactive(function() {
values <- lapply(dists[[input$popDist]]$params, function(param) {
input[param]
})
names(values) <- dists[[input$popDist]]$params
values
})
rdist <- reactive(function() {
dists[[input$popDist]]$func
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment