-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshinyApp3.R
More file actions
60 lines (44 loc) · 1.33 KB
/
shinyApp3.R
File metadata and controls
60 lines (44 loc) · 1.33 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
49
50
51
52
53
54
55
56
57
58
59
60
# https://github.com/rstudio-education/shiny.rstudio.com-tutorial
rm(list=ls())
library(shiny)
library(ggplot2)
ui <- fluidPage(
headerPanel("Hello Shiny!"),
sidebarPanel(
sliderInput(inputId = "sample",
label = "Choose a sample",
value = 500, min = 100, max = 1000),
sliderInput(inputId = "num",
label = "Choose a offset",
value = 25, min = 1, max = 100),
sliderInput(inputId = "sd",
label = "Choose a s.d.",
value = 10, min = 1, max = 20),
textInput(inputId = "title",
label = "Write a title",
value = "Histogram of Random Normal Values")
),
mainPanel(
plotOutput("hist")
)
)
server <- function(input, output) {
output$hist <- renderPlot({
n<-input$sample
offset<-input$num/5
mean1 = 50 - offset
mean2 = 50 + offset
sd = input$sd
df <- data.frame(
sex=factor(rep(c("F", "M"), each=n)),
weight=round(c(rnorm(n, mean=mean1, sd=sd), rnorm(n, mean=mean2, sd=sd)))
)
ggplot(df, aes(x=weight, color=sex)) +
geom_density(alpha=.5, fill="white") +
scale_color_brewer(palette="Accent") +
theme_minimal() +
labs(title=input$title) +
theme(legend.position="top")
})
}
shinyApp(ui, server)