-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
77 lines (61 loc) · 2.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Log Stats Viewer
# Allows user to interactively browse the results of a log parse.
# Henry J Schmale
library(shiny)
library(dplyr)
library(ggplot2)
library(lubridate)
articleViews <- read.csv('../articleViews.csv', header = FALSE)
colnames(articleViews) <- c('path', 'date', 'hits')
articleViews$date <- as.Date(articleViews$date)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Log Analysis"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("range",
"Date Range:",
min = min(articleViews$date),
max = max(articleViews$date),
value = c(min(articleViews$date), max(articleViews$date))),
selectInput("group_by_ts",
"Group By Time Unit:",
c("day", "week", "month"))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("viewHeatPlot"),
plotOutput("overallViewsPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$viewHeatPlot <- renderPlot({
rng <- input$range
groupedHitsOverTs <- filter(articleViews, date >= rng[1], date <= rng[2]) %>%
group_by(path, date = floor_date(date, input$group_by_ts)) %>%
summarise(hits = sum(hits))
ggplot(groupedHitsOverTs, aes(x = path, y = date, fill = hits)) +
geom_tile() +
# geom_text(aes(label=hits)) +
coord_flip() +
scale_fill_continuous(low='blue', high='red')
})
output$overallViewsPlot <- renderPlot({
rng <- input$range
hitsOverRng <- filter(articleViews, date >= rng[1], date <= rng[2]) %>%
group_by(path) %>%
summarise(hits = sum(hits))
ggplot(hitsOverRng, aes(x = path, y = hits)) +
geom_bar(stat = 'identity') +
theme(axis.text.x = element_text(angle = 75, hjust = 1))
})
output$text <- renderText({
input$group_by_ts
})
}
# Run the application
shinyApp(ui = ui, server = server)