-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshinyApp2.R
More file actions
46 lines (32 loc) · 964 Bytes
/
shinyApp2.R
File metadata and controls
46 lines (32 loc) · 964 Bytes
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
# https://github.com/rstudio-education/shiny.rstudio.com-tutorial
rm(list=ls())
library(shiny)
library(ggplot2)
ui <- fluidPage(
titlePanel("Hello Shiny!"),
sliderInput(inputId = "num",
label = "Choose a offset",
value = 25, min = 1, max = 100),
textOutput("greeting"),
plotOutput("hist")
)
server <- function(input, output) {
output$greeting <- renderText(paste("Offset is ", input$num))
output$hist <- renderPlot({
n<-1000
offset<-input$num/5
mean1 = 50 - offset
mean2 = 50 + offset
sd = 10
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() +
theme(legend.position="top")
})
}
shinyApp(ui, server)