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

91 lines
2.5 KiB
R
Raw Normal View History

2019-05-15 19:56:07 +02:00
#
# RESULTS
#
# Results with pagination
2019-05-19 00:07:35 +02:00
getFilteredResultsForTeam <- function(input) {
getMatchesForTeam(football_data, input$team) %>%
2019-05-19 01:33:04 +02:00
filterByDate(as_date(input$date_range_for_team[1]), as_date(input$date_range_for_team[2]))
2019-05-19 00:07:35 +02:00
}
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
)
)
}
2019-05-19 00:07:35 +02:00
matchesForTeam <- function(input, output) {
output$matches_for_team <- DT::renderDataTable(
getFilteredResultsForTeam(input),
extensions = 'Buttons',
options = list(
lengthMenu = list(c(5, 10, -1), c('5', '10', '20', 'All')),
pageLength = 20,
searching = FALSE
)
)
}
# Balance
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
}
2019-05-19 01:33:04 +02:00
getBalanceDataForTeamBarplot <- function(input) {
return(
getBalanceForTeam(getFilteredResultsForTeam(input), input$team)
)
}
balanceForTeamBarplot <- function(input, output) {
output$balance_for_team <- renderPlot({
ggplot(getBalanceDataForTeamBarplot(input),
aes(x=as.factor(winner), y=as.factor(n))) +
geom_bar(stat = "identity", fill = rgb(0.6, 0.1, 0.4, 0.7)) +
theme_minimal() +
labs(x = "", y = "Matches balance for")
})
}
2019-05-15 19:56:07 +02:00
# Balance percentage
2019-05-19 01:33:04 +02:00
getBalanceData <- function(input) {
getBalance(getFilteredResults(input))
}
2019-05-15 19:56:07 +02:00
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() +
2019-05-19 00:07:35 +02:00
geom_text(aes(x=1,
y = cumsum(percentage) - percentage/2,
label = percent(percentage)))
2019-05-15 19:56:07 +02:00
})
2019-05-19 19:05:06 +02:00
}
# Summary statistics
summaryStatistics <- function(input, output) {
output$summary_statistics <- renderTable(
goalsScored(getFilteredResultsForTeam(input), input$team)
)
2019-05-19 01:33:04 +02:00
}