Added pie chart
This commit is contained in:
parent
d7e82ad610
commit
06ca590748
22
Server/DataProcessor.R
Normal file
22
Server/DataProcessor.R
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# DATA PROCESSING
|
||||
#
|
||||
|
||||
# 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)
|
||||
}
|
||||
|
||||
getBalancePercentage <- function(balance) {
|
||||
balancePerc <- balance %>%
|
||||
mutate(percentage = n/sum(.$n) * 100)
|
||||
}
|
@ -1,16 +1,6 @@
|
||||
# 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
|
||||
#
|
||||
|
||||
# Results with pagination
|
||||
resultsWithPagination <- function(input, output) {
|
||||
@ -29,10 +19,26 @@ resultsWithPagination <- function(input, output) {
|
||||
balanceBetweenTeams <- function(input, output) {
|
||||
output$balance <- renderPlot({
|
||||
barplot(
|
||||
bal <- getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))$n,
|
||||
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
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
# Balance percentage
|
||||
balancePercentage <- function(input, output) {
|
||||
output$balancePieChart <- renderPlot({
|
||||
pie(
|
||||
getBalancePercentage(
|
||||
getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))
|
||||
)$percentage,
|
||||
main = "Match balance (percentage)",
|
||||
labels = getBalancePercentage(
|
||||
getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))
|
||||
)$winner,
|
||||
col = rainbow(3)
|
||||
)
|
||||
})
|
||||
}
|
@ -4,9 +4,11 @@
|
||||
|
||||
# Import files
|
||||
source("Server/Results.R")
|
||||
source("Server/DataProcessor.R")
|
||||
|
||||
# Server logic
|
||||
server <- function(input, output) {
|
||||
balanceBetweenTeams(input, output)
|
||||
balancePercentage(input, output)
|
||||
resultsWithPagination(input, output)
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ source("UI/SidebarPanel.R")
|
||||
|
||||
# UI
|
||||
ui <- fluidPage(
|
||||
theme = shinytheme("slate"),
|
||||
|
||||
# Application title
|
||||
titlePanel("International football results 1872-2018"),
|
||||
@ -18,6 +19,7 @@ ui <- fluidPage(
|
||||
# Main panel
|
||||
mainPanel(
|
||||
plotOutput("balance"),
|
||||
plotOutput("balancePieChart"),
|
||||
DT::dataTableOutput("results_pagination")
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user