-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
55 lines (38 loc) · 1.21 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
library(shiny)
library(ggplot2)
source("../global.R")
ui <- fluidPage(
# Application title
titlePanel("DataSchool Pace Responses"),
textInput("timePeriod", "Time period (in hours)", value = 3),
plotOutput("responsePlot")
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
readData <- reactiveFileReader(1000,
session,
"../data/responses.csv",
read.csv,
header = FALSE)
getData <- function() {
dat <- readData()
currentTime <- Sys.time()
timePeriod <- as.numeric(input$timePeriod)
dat <- dat[difftime(currentTime, dat$V1, units = "hours") < timePeriod,]
return(dat)
}
output$responsePlot <- renderPlot({
dat <- getData()
p <- ggplot(dat, aes(V2)) +
geom_bar() +
stat_count(aes(y = after_stat(count), label = after_stat(count)),
geom = "text", vjust = -1) +
ylab("Responses") +
xlab("") +
labs() +
theme_minimal()
return(p)
})
}
# Run the application
shinyApp(ui = ui, server = server)