38 lines
1.1 KiB
R
38 lines
1.1 KiB
R
|
# Functions
|
||
|
getMatchesList <- function(first_team, second_team, football_data) {
|
||
|
matches <- football_data %>%
|
||
|
filter(home_team %in% c(first_team, second_team)
|
||
|
& away_team %in% c(first_team, second_team))
|
||
|
return(matches)
|
||
|
}
|
||
|
|
||
|
getBalance <- function(football_data) {
|
||
|
balance <- football_data %>%
|
||
|
count(winner, sort = TRUE)
|
||
|
return(balance)
|
||
|
}
|
||
|
|
||
|
# Results with pagination
|
||
|
resultsWithPagination <- function(input, output) {
|
||
|
output$results_pagination <- DT::renderDataTable(
|
||
|
getMatchesList(input$first_team, input$second_team, football_data),
|
||
|
extensions = 'Buttons',
|
||
|
options = list(
|
||
|
lengthMenu = list(c(5, 10, -1), c('5', '10', 'All')),
|
||
|
pageLength = 10,
|
||
|
searching = FALSE
|
||
|
)
|
||
|
)
|
||
|
}
|
||
|
|
||
|
# Balance
|
||
|
balanceBetweenTeams <- function(input, output) {
|
||
|
output$balance <- renderPlot({
|
||
|
barplot(
|
||
|
bal <- getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))$n,
|
||
|
main = "Balance between teams",
|
||
|
col = rainbow(3),
|
||
|
names.arg = getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))$winner
|
||
|
)
|
||
|
})
|
||
|
}
|