-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshinyApp6a.R
More file actions
48 lines (39 loc) · 1.56 KB
/
shinyApp6a.R
File metadata and controls
48 lines (39 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# https://github.com/rstudio-education/shiny.rstudio.com-tutorial/tree/master/part-3-code
rm(list=ls())
library(shiny)
ui <- navbarPage(title = "Random generator",
tabPanel(title = "Normal data",
plotOutput("norm"),
actionButton("renorm", "Resample")
),
tabPanel(title = "Uniform data",
plotOutput("unif"),
actionButton("reunif", "Resample")
),
tabPanel(title = "Chi Squared data",
plotOutput("chisq"),
actionButton("rechisq", "Resample")
)
)
server <- function(input, output) {
rv <- reactiveValues(
norm = rnorm(500),
unif = runif(500),
chisq = rchisq(500, 2))
observeEvent(input$renorm, { rv$norm <- rnorm(500) })
observeEvent(input$reunif, { rv$unif <- runif(500) })
observeEvent(input$rechisq, { rv$chisq <- rchisq(500, 2) })
output$norm <- renderPlot({
hist(rv$norm, breaks = 30, col = "grey", border = "white",
main = "500 random draws from a standard normal distribution")
})
output$unif <- renderPlot({
hist(rv$unif, breaks = 30, col = "grey", border = "white",
main = "500 random draws from a standard uniform distribution")
})
output$chisq <- renderPlot({
hist(rv$chisq, breaks = 30, col = "grey", border = "white",
main = "500 random draws from a Chi Square distribution with two degree of freedom")
})
}
shinyApp(ui, server)