Skip to content

Instantly share code, notes, and snippets.

@JoFAM
Created September 12, 2019 16:19
Show Gist options
  • Save JoFAM/b283edcad3dd3ae9ffecd076eb87bbe7 to your computer and use it in GitHub Desktop.
Save JoFAM/b283edcad3dd3ae9ffecd076eb87bbe7 to your computer and use it in GitHub Desktop.
An example of a shiny App that can be run from a Gist
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
mysamples <- reactive({
fdist <- switch(input$dist,
Normal = rnorm,
Exponential = rexp,
Poisson = function(n) rpois(n,4))
replicate(input$p, fdist(input$n))
})
output$thehist <- renderPlot({
hist(colMeans(mysamples()),
col = "blue")
})
})
library(shiny)
# Define UI for application that draws a histogram
fluidPage(
# Application title
titlePanel("Central Limit Theorem"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("n",
"Number of observations:",
min = 5,
max = 50,
value = 30),
sliderInput("p",
"Number of samples",
min = 20, max = 1000,
value = 500),
selectInput("dist",
"Select a distribution",
choices = c("Normal","Exponential",
"Poisson"))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("thehist")
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment