-
Notifications
You must be signed in to change notification settings - Fork 54
/
app.R
57 lines (46 loc) · 1.14 KB
/
app.R
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
49
50
51
52
53
54
55
56
57
library(shiny)
ui <- fluidPage(
selectInput(
"n_breaks",
label = "Number of bins in histogram (approximate):",
choices = c(10, 20, 35, 50),
selected = 20
),
checkboxInput(
"individual_obs",
label = strong("Show individual observations"),
value = FALSE
),
checkboxInput(
"density",
label = strong("Show density estimate"),
value = FALSE
),
plotOutput("main_plot", height = "300px"),
# Display this only if the density is shown
conditionalPanel(condition = "input.density == true",
sliderInput(
"bw_adjust",
label = "Bandwidth adjustment:",
min = 0.2, max = 2, value = 1, step = 0.2)
)
)
server <- function(input, output) {
output$main_plot <- renderPlot({
hist(
faithful$eruptions,
probability = TRUE,
breaks = as.numeric(input$n_breaks),
xlab = "Duration (minutes)",
main = "Geyser eruption duration"
)
if (input$individual_obs) {
rug(faithful$eruptions)
}
if (input$density) {
dens <- density(faithful$eruptions, adjust = input$bw_adjust)
lines(dens, col = "blue")
}
})
}
shinyApp(ui, server)