-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
107 lines (96 loc) · 3.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
library(shiny)
library(dplyr)
source("src/functions.R")
herringsFilename <- 'files/herrings.csv'
herringImageFile <-"img/herring.png"
transformedData <- transformData(loadData(herringsFilename))
data <- addYearsColumns(transformedData)
meanByYear <- data %>% group_by(year) %>% summarise_at(vars(length), mean)
scaleHerringSizeForUI <- function(size)
{
size*20
}
getLengthFromYear <- function(year)
{
scaleHerringSizeForUI(meanByYear[year, 2])
}
createYearPlot <- function(year_point)
{
ggplot(meanByYear, aes(x=year, y=length)) +
geom_line(linetype = "dashed") +
geom_point(aes(x=year_point, y=as.numeric(meanByYear[year_point, 2])), colour="red", size=5) +
labs(title="Rozkład długości śledzia w zależności od roku",
subtitle = "Agregacja na podstawie założenia o chronologii danych.",
x="Rok",
y="Długość śledzia [cm]")
}
getExtremeHerringSize <- function(minMaxFunction)
{
length <- minMaxFunction(meanByYear$length)
year <- meanByYear[meanByYear$length == length, 1]
list(year=year, length=round(length, 2))
}
min.size <- getExtremeHerringSize(min)
max.size <- getExtremeHerringSize(max)
ui <-
navbarPage("Analiza długości śledzia",
tabPanel("Raport",
includeMarkdown("README.md")
),
tabPanel("Animacja długości śledzia",
fluidPage(
fluidRow(
column(width=3,
h2("Rok"),
sliderInput("slider", label = "", min = min(data$year), max = max(data$year), value = min(data$year) + (max(data$year) - min(data$year))/2 )
),
column(width=5, class="currentHerringRow",
h3("Aktualny śledź"),
textOutput("herringYearText"),
textOutput("herringSizeText"),
uiOutput('herringImg')
),
column(width=4,
plotOutput("herringPlot")
)
),
fluidRow(
column(offset=3, width=5, class="minHerringRow",
h3("Minimalny rozmiar"),
p("Rok", min.size$year),
p("Rozmiar", min.size$length, "cm"),
img(src = herringImageFile, width = scaleHerringSizeForUI(min.size$length))
)
),
fluidRow(
column(offset=3, width=5, class="maxHerringRow",
h3("Maksymalny rozmiar"),
p("Rok", max.size$year),
p("Rozmiar", max.size$length, "cm"),
img(src = herringImageFile, width = scaleHerringSizeForUI(max.size$length))
)
),
tags$head(
tags$style(
".currentHerringRow{ background-color: #66b3ff; }
.minHerringRow{ background-color: #79d2a6; }
.maxHerringRow{ background-color: #ff9999; }"
)
)
)
)
)
server <- function(input, output, session) {
year <- reactive(as.integer(input$slider))
output$herringImg <- renderUI({
img(src = herringImageFile, width = getLengthFromYear(year()))
})
output$herringYearText <- renderText({
paste("Rok ", year())
})
output$herringSizeText <- renderText({
paste("Rozmiar ", round(meanByYear[year(), 2], 2), "cm")
})
output$herringPlot <- renderPlot(createYearPlot(year()))
}
shinyApp(ui, server)