TPD-InternationalFootballRe.../Server/Results.R

49 lines
1.3 KiB
R
Raw Normal View History

2019-05-15 19:56:07 +02:00
#
# RESULTS
#
# Results with pagination
getFilteredResults <- function(input) {
getMatchesList(football_data, input$first_team, input$second_team) %>%
filterByDate(as_date(input$date_range[1]), as_date(input$date_range[2]))
}
resultsWithPagination <- function(input, output) {
output$results_pagination <- DT::renderDataTable(
getFilteredResults(input),
extensions = 'Buttons',
options = list(
lengthMenu = list(c(5, 10, -1), c('5', '10', 'All')),
pageLength = 10,
searching = FALSE
)
)
}
# Balance
getBalanceData <- function(input) {
getBalance(getFilteredResults(input))
}
balanceBetweenTeams <- function(input, output) {
output$balance <- renderPlot({
2019-05-16 00:37:48 +02:00
ggplot(getFilteredResults(input), aes(x=as.factor(winner),
fill=as.factor(n))) +
geom_bar(fill = rgb(0.1,0.4,0.5,0.7)) +
theme_minimal() +
labs(x = "", y = "Number of matches")
})
2019-05-15 19:56:07 +02:00
}
# Balance percentage
balancePercentage <- function(input, output) {
output$balancePieChart <- renderPlot({
2019-05-16 00:37:48 +02:00
ggplot(getBalancePercentage(getBalanceData(input))) +
geom_bar(
aes(x="", y=percentage, fill=winner),
stat = "identity") +
coord_polar("y", start = 0) +
theme_void() +
geom_text(aes(x=1, y = cumsum(percentage) - percentage/2, label = percent(percentage)))
2019-05-15 19:56:07 +02:00
})
}