Created
September 12, 2019 16:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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