# # RESULTS # # Results with pagination getFilteredResultsForTeam <- function(input) { getMatchesForTeam(football_data, input$team) %>% filterByDate(as_date(input$date_range_for_team[1]), as_date(input$date_range_for_team[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 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") }) } 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") }) } # Balance percentage getBalanceData <- function(input) { getBalance(getFilteredResults(input)) } 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))) }) } # Summary statistics summaryStatistics <- function(input, output) { output$summary_statistics <- renderTable( goalsScored(getFilteredResultsForTeam(input), input$team) ) }