70 lines
1.9 KiB
R
70 lines
1.9 KiB
R
#
|
|
# RESULTS
|
|
#
|
|
|
|
# Results with pagination
|
|
getFilteredResultsForTeam <- function(input) {
|
|
getMatchesForTeam(football_data, input$team) %>%
|
|
filterByDate(as_date(input$date_range[1]), as_date(input$date_range[2]))
|
|
}
|
|
|
|
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
|
|
)
|
|
)
|
|
}
|
|
|
|
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
|
|
getBalanceData <- function(input) {
|
|
getBalance(getFilteredResults(input))
|
|
}
|
|
|
|
balanceBetweenTeams <- function(input, output) {
|
|
output$balance <- renderPlot({
|
|
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")
|
|
})
|
|
}
|
|
|
|
# Balance percentage
|
|
balancePercentage <- function(input, output) {
|
|
output$balancePieChart <- renderPlot({
|
|
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)))
|
|
})
|
|
}
|
|
|
|
# Top teams barplot |