# # 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({ 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))) }) }