diff --git a/.RData b/.RData index 5e97baf..62140d2 100644 Binary files a/.RData and b/.RData differ diff --git a/.Rhistory b/.Rhistory index 0df18df..df7ff41 100644 --- a/.Rhistory +++ b/.Rhistory @@ -277,3 +277,229 @@ runApp() runApp() runApp() runApp() +shiny::runApp() +install.packages("shinythemes") +runApp() +runApp() +runApp() +View(test) +View(balance) +View(bal) +balancePercTest <- bal %>% mutate(percentage = n/sum(.$n)) +head(balancePercTest) +runApp() +runApp() +runApp() +runApp() +runApp() +balPerc <- getBalancePercentage( +getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext)) +) +runApp() +runApp() +runApp() +runApp() +View(football_data) +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +View(football_data) +getMatchesList("England", "Scotland", football_data) +getMatchesList("England", "Scotland", football_data) %>% arrange() +getMatchesList("England", "Scotland", football_data) %>% arrange(decreasing=TRUE) +getMatchesList("England", "Scotland", football_data) %>% arrange(.,decreasing=TRUE) +getMatchesList("England", "Scotland", football_data) %>% arrange(.$date) +getMatchesList("England", "Scotland", football_data) %>% arrange(.$date, decreasing=TRUE) +getMatchesList("England", "Scotland", football_data) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% sort(date) +getMatchesList("England", "Scotland", football_data) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% sort(date, decreasing = TRUE) +football_data %>% select(date) +football_data %>% select(date) %>% min() +football_data %>% select(date) %>% format(date, "%Y") +football_data %>% select(date) %>% format(.$date, "%Y") +football_data %>% select(date) %>% typeof() +football_data %>% select(date) %>% format(as.Date(date, format="%Y-%m-%d"),"%Y") +test <- football_data %>% select(date) +test[1] +test %>% head(1) +test %>% head(1) %>% format(., "%Y") +test %>% head(1) %>% typeof +test %>% head(1) %>% typeof() +football_data %>% select(date) %>% min() +football_data %>% select(date) +football_data %>% select(date) %>% aggregate(., by=list(.), max) +football_data %>% min(.$date) +football_data %>% select(date) %>% summarise(min = min(date)) +football_data %>% select(date) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% summarise(min = min(date)) +football_data %>% select(date) %>% mutate(. = as.Date(date, "%Y-%m-%d")) %>% summarise(min = min(.)) +football_data %>% select(date) %>% mutate(. = as.Date(., "%Y-%m-%d")) %>% summarise(min = min(.)) +getDateFromData <- function(matchesData) { +return( +matchesData %>% +select(date) %>% +mutate(date = as.Date(date, "%Y-%m-%d")) +) +} +getDateFromData(football_data) %>% +summarise(max = max(date)) +balance <- football_data %>% +count(winner, sort = TRUE) +return(balance) +runApp() +getDateFromData(football_data) +runApp() +runApp() +runApp() +runApp() +typeof(min_date_from) +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% as.Date() +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% as.Date(., format = "%Y-%m-%d") +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% as.Date(date, format = "%Y-%m-%d") +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% as.Date(date) +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% strptime(date, "%Y-%m-%d") +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% strptime(., "%Y-%m-%d") +getDateFromData(football_data) %>% +summarise(min = min(date)) +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% top_n(1) +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% top_n(1) %>% typeof +runApp() +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% slice(1) +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% pull() +runApp() +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% pull() %>% typeof() +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% pull() %>% as.Date(., format = "%Y-%m-%d") +getDateFromData(football_data) %>% +summarise(min = min(date)) %>% pull() %>% as.Date(., format = "%Y-%m-%d") %>% typeof() +test <- getDateFromData(football_data) %>% +summarise(min = min(date)) %>% pull() +as.Date(test, "%Y-%m-%d") +as.Date(test, "%Y-%m-%d") %>% typeof() +test <- as.Date(test, "%Y-%m-%d") +typeof(test) +as.character(test) +test <- as.character(test) +test +typeof(test) +test <- as.Date(test, "%Y-%m-%d") +test +typeof(test) +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +test_date <- as.Date("2000-01-01", "%Y-%m-%d") +football_data %>% filter(as.Date(as.character(date, "%Y-%d-%m")) >= test_date) +runApp() +football_data %>% +filter(as.Date(as.character(date, "%Y-%d-%m")) >= as.Date(as.character(test_date, "%Y-%d-%m")) +& as.Date(as.character(date, "%Y-%d-%m")) <= as.Date(as.character(max_date_to, "%Y-%d-%m"))) +football_data %>% +filter(as.Date(as.character(date, "%Y-%d-%m")) >= as.Date(as.character(test_date, "%Y-%d-%m"))) +runApp() +install.packages("lubridate") +runApp() +runApp() +dateFrom <- as.Date(as.character(dateFrom, "%Y-%m-%d")) +runApp() +as_date(test) +test_date <- as_date(test) +test_date +typeof(test_date) +runApp() +runApp() +runApp() +football_data %>% filter(as_date(date) >= test_date) +runApp() +getMatchesList <- function(matchesData, first_team, second_team) { +return( +matchesData %>% +filter(home_team %in% c(first_team, second_team) +& away_team %in% c(first_team, second_team)) %>% +arrange() +) +} +getMatchesList(football_data, "England", "Scotland") +getMatchesList(football_data, "England", "Scotland") %>% filterByDate(min_date_from, max_date_to) +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +View(football_data_ext) +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +install.packages("shinydashboard") +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() +runApp() diff --git a/Server/DataProcessor.R b/Server/DataProcessor.R index 4ae2871..3e7f35b 100644 --- a/Server/DataProcessor.R +++ b/Server/DataProcessor.R @@ -28,5 +28,5 @@ getBalance <- function(football_data) { getBalancePercentage <- function(balance) { balancePerc <- balance %>% - mutate(percentage = n/sum(.$n) * 100) + mutate(percentage = n/sum(.$n)) } \ No newline at end of file diff --git a/Server/Results.R b/Server/Results.R index ac5b582..eb9cb19 100644 --- a/Server/Results.R +++ b/Server/Results.R @@ -27,27 +27,23 @@ getBalanceData <- function(input) { balanceBetweenTeams <- function(input, output) { output$balance <- renderPlot({ - barplot( - getBalanceData(input)$n, - main = "Balance between teams", - col = rainbow(3), - names.arg = getBalanceData(input)$winner - ) + 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({ - pie( - getBalancePercentage( - getBalanceData(input) - )$percentage, - main = "Match balance (percentage)", - labels = getBalancePercentage( - getBalanceData(input) - )$winner, - col = rainbow(3) - ) + 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))) }) } \ No newline at end of file diff --git a/Server/main.R b/Server/Server.R similarity index 100% rename from Server/main.R rename to Server/Server.R diff --git a/UI/BalanceComponent.R b/UI/BalanceComponent.R new file mode 100644 index 0000000..e29b2c2 --- /dev/null +++ b/UI/BalanceComponent.R @@ -0,0 +1,17 @@ +# Balance component + +balanceComponent <- function(pieChartSize, barplotSize) +{ + fluidRow( + column(barplotSize, + wellPanel( + plotOutput("balance") + ) + ), + column(pieChartSize, + wellPanel( + plotOutput("balancePieChart") + ) + ) + ) +} diff --git a/UI/UI.R b/UI/UI.R new file mode 100644 index 0000000..efdfb72 --- /dev/null +++ b/UI/UI.R @@ -0,0 +1,30 @@ +# +# Main UI File +# + +# Import files +source("UI/SidebarPanel.R") +source("UI/BalanceComponent.R") + +# UI +ui <- fluidPage( + theme = shinytheme("cerulean"), + + # Application title + headerPanel("International football results 1872-2018"), + + # Sidebar layout elements + sidebarLayout( + teamsSidebarPanel(), + + # Main panel + mainPanel( + fluidPage( + balanceComponent(6, 6), + fluidRow( + DT::dataTableOutput("results_pagination") + ) + ) + ) + ) +) \ No newline at end of file diff --git a/UI/main.R b/UI/main.R deleted file mode 100644 index 70ee5b6..0000000 --- a/UI/main.R +++ /dev/null @@ -1,26 +0,0 @@ -# -# Main UI File -# - -# Import files -source("UI/SidebarPanel.R") - -# UI -ui <- fluidPage( - theme = shinytheme("slate"), - - # Application title - titlePanel("International football results 1872-2018"), - - # Sidebar layout elements - sidebarLayout( - teamsSidebarPanel(), - - # Main panel - mainPanel( - plotOutput("balance"), - plotOutput("balancePieChart"), - DT::dataTableOutput("results_pagination") - ) - ) -) \ No newline at end of file diff --git a/app.R b/app.R index 17391a4..821e265 100644 --- a/app.R +++ b/app.R @@ -11,11 +11,13 @@ library(shiny) library(dplyr) library(shinythemes) library(lubridate) +library(ggplot2) +library(scales) # Load files source("Data/Loader.R") -source("UI/main.R") -source("Server/main.R") +source("UI/UI.R") +source("Server/Server.R") # Run the application shinyApp(ui = ui, server = server)