Initial commit
This commit is contained in:
commit
c17dfb82d7
157
.Rhistory
Normal file
157
.Rhistory
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
shiny::runApp()
|
||||||
|
runApp()
|
||||||
|
# Load data
|
||||||
|
football_data <- read.csv("results.csv")
|
||||||
|
head(football_data)
|
||||||
|
football_data <- as_tibble(read.csv("results.csv"))
|
||||||
|
library(dplyr)
|
||||||
|
football_data <- as_tibble(read.csv("results.csv"))
|
||||||
|
football_data %>% select(2)
|
||||||
|
football_data %>% select("home_team")
|
||||||
|
football_data %>% select("home_team") %>% unique()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
shiny::runApp()
|
||||||
|
runApp(display.mode = "showcase")
|
||||||
|
runApp(display.mode = "showcase")
|
||||||
|
runApp()
|
||||||
|
get_matches_list <- function(home_team, away_team) {
|
||||||
|
matches <- football_data %>%
|
||||||
|
select(1:5) %>%
|
||||||
|
filter("home_team" == home_team
|
||||||
|
& "away_team" == away_team)
|
||||||
|
return(matches)
|
||||||
|
}
|
||||||
|
get_matches_list("Scotland", "England")
|
||||||
|
head(get_matches_list("Scotland", "England"))
|
||||||
|
test <- get_matches_list("Scotland", "England")
|
||||||
|
test <- get_matches_list("Poland", "England")
|
||||||
|
test
|
||||||
|
football_data %>% filter("home_team" == "England")
|
||||||
|
football_data %>% filter(1 == "England")
|
||||||
|
football_data %>% filter(2 == "England")
|
||||||
|
matches <- football_data %>%
|
||||||
|
select(1:5) %>%
|
||||||
|
filter("home_team" %in% c(first_team, second_team)
|
||||||
|
& "away_team" %>% c(first_team, second_team))
|
||||||
|
matches <- football_data %>%
|
||||||
|
select(1:5) %>%
|
||||||
|
filter("home_team" %in% c("England")
|
||||||
|
)
|
||||||
|
football_data %>% filter(str_detect("home_team", "England")
|
||||||
|
)
|
||||||
|
library(stringr)
|
||||||
|
football_data %>% filter(str_detect("home_team", "England")_
|
||||||
|
football_data %>% filter(str_detect("home_team", "England"))
|
||||||
|
football_data %>% filter(str_detect(2, "England"))
|
||||||
|
football_data %>% filter(home_team == "England")
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
football_data_ext <- football_data %>%
|
||||||
|
select(2:4)
|
||||||
|
head(football_data_ext)
|
||||||
|
football_data_ext <- football_data %>%
|
||||||
|
select(2:6)
|
||||||
|
head(football_data_ext)
|
||||||
|
head(football_data)
|
||||||
|
football_data["home_team"]
|
||||||
|
get_winner_name <- function(match_row) {
|
||||||
|
if(match_row["home_score"] > match_row["away_score"]) {
|
||||||
|
return(match_row["home_team"])
|
||||||
|
}
|
||||||
|
else if(match_row["home_score"] < match_row["away_score"]) {
|
||||||
|
return(match_row["away_team"])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return("Draw")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get_winner_name(football_data[0])
|
||||||
|
head(football_data)
|
||||||
|
get_winner_name(football_data[1])
|
||||||
|
football_data[1]
|
||||||
|
football_data[, 1]
|
||||||
|
top_n(football_data, 1)
|
||||||
|
football_data %>% slice(1)
|
||||||
|
football_data %>% slice(1) %>% get_winner_name()
|
||||||
|
football_data %>% select(2:5) %>% get_winner_name()
|
||||||
|
football_data %>% select(2:5)
|
||||||
|
football_data %>% select(2:5) %>% mutate(get_winner_name())
|
||||||
|
football_data %>% select(2:5) %>% mutate(get_winner_name(.))
|
||||||
|
football_data %>% select(2:5) %>% mutate(result = get_winner_name(.))
|
||||||
|
football_data %>% select(2:5) %>% rowwise() %>% mutate(result = get_winner_name(.))
|
||||||
|
warnings()
|
||||||
|
football_data %>% select(2:5) %>% rowwise() %>% mutate(result = get_winner_name())
|
||||||
|
football_data %>%
|
||||||
|
select(2:5) %>% mutate(get_winner_name(home_score, away_score, home_team, away_team))
|
||||||
|
get_winner_name <- function(home_score, away_score, home_team, away_team) {
|
||||||
|
if(home_score > away_score) {
|
||||||
|
return(home_team)
|
||||||
|
}
|
||||||
|
else if(home_score < away_score) {
|
||||||
|
return(away_team)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return("Draw")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
football_data %>%
|
||||||
|
select(2:5) %>% mutate(get_winner_name(home_score, away_score, home_team, away_team))
|
||||||
|
football_data %>%
|
||||||
|
select(2:5) %>% mutate(winner = get_winner_name(home_score, away_score, home_team, away_team))
|
||||||
|
football_data %>% slice(2)
|
||||||
|
football_data %>% slice(2) %>% get_winner_name()
|
||||||
|
get_winner_name <- function(match_row) {
|
||||||
|
if(match_row["home_score"] > match_row["away_score"]) {
|
||||||
|
return(match_row["home_team"])
|
||||||
|
}
|
||||||
|
else if(match_row["home_score"] < match_row["away_score"]) {
|
||||||
|
return(match_row["away_team"])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return("Draw")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get_winner_name <- function(match_row) {
|
||||||
|
if(match_row["home_score"] > match_row["away_score"]) {
|
||||||
|
return(match_row["home_team"])
|
||||||
|
}
|
||||||
|
else if(match_row["home_score"] < match_row["away_score"]) {
|
||||||
|
return(match_row["away_team"])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return("Draw")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
football_data %>% slice(2) %>% get_winner_name()
|
||||||
|
football_data %>% get_winner_name()
|
||||||
|
football_data %>% rowwise() %>% get_winner_name()
|
||||||
|
football_data %>% apply(get_winner_name())
|
||||||
|
football_data %>% apply(., get_winner_name())
|
||||||
|
football_data %>% apply(., ,get_winner_name())
|
||||||
|
football_data %>% apply(., ,get_winner_name)
|
||||||
|
football_data %>% apply(., 1, get_winner_name)
|
||||||
|
football_data %>% mutate(winner = apply(., 1, get_winner_name))
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
2
.Rproj.user/812E148F/sources/prop/AF44A8
Normal file
2
.Rproj.user/812E148F/sources/prop/AF44A8
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
1
.Rproj.user/812E148F/sources/prop/INDEX
Normal file
1
.Rproj.user/812E148F/sources/prop/INDEX
Normal file
@ -0,0 +1 @@
|
|||||||
|
j%3A%2FDesktop%2FTPD%2FShinyAppExample%2Fapp.R="AF44A8"
|
20
.Rproj.user/812E148F/sources/s-83ED6DC2/42023A5F
Normal file
20
.Rproj.user/812E148F/sources/s-83ED6DC2/42023A5F
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"collab_server" : "",
|
||||||
|
"contents" : "",
|
||||||
|
"created" : 1557865362146.000,
|
||||||
|
"dirty" : false,
|
||||||
|
"encoding" : "UTF-8",
|
||||||
|
"folds" : "",
|
||||||
|
"hash" : "2571298282",
|
||||||
|
"id" : "42023A5F",
|
||||||
|
"lastKnownWriteTime" : 1557788269,
|
||||||
|
"last_content_update" : 1557788269,
|
||||||
|
"path" : "j:/Desktop/TPD/ShinyAppExample/app.R",
|
||||||
|
"project_path" : "app.R",
|
||||||
|
"properties" : {
|
||||||
|
},
|
||||||
|
"relative_order" : 1,
|
||||||
|
"source_on_save" : false,
|
||||||
|
"source_window" : "",
|
||||||
|
"type" : "r_source"
|
||||||
|
}
|
87
.Rproj.user/812E148F/sources/s-83ED6DC2/42023A5F-contents
Normal file
87
.Rproj.user/812E148F/sources/s-83ED6DC2/42023A5F-contents
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#
|
||||||
|
# This is a Shiny web application. You can run the application by clicking
|
||||||
|
# the 'Run App' button above.
|
||||||
|
#
|
||||||
|
# Find out more about building applications with Shiny here:
|
||||||
|
#
|
||||||
|
# http://shiny.rstudio.com/
|
||||||
|
#
|
||||||
|
|
||||||
|
library(shiny)
|
||||||
|
library(dplyr)
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
get_matches_list <- function(first_team, second_team) {
|
||||||
|
matches <- football_data %>%
|
||||||
|
select(1:9) %>%
|
||||||
|
filter(home_team %in% c(first_team, second_team)
|
||||||
|
& away_team %in% c(first_team, second_team))
|
||||||
|
return(matches)
|
||||||
|
}
|
||||||
|
|
||||||
|
get_winner_name <- function(match_row) {
|
||||||
|
if(match_row["home_score"] > match_row["away_score"]) {
|
||||||
|
return(match_row["home_team"])
|
||||||
|
}
|
||||||
|
else if(match_row["home_score"] < match_row["away_score"]) {
|
||||||
|
return(match_row["away_team"])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return("Draw")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load data
|
||||||
|
football_data <- as_tibble(read.csv("results.csv"))
|
||||||
|
football_data_ext <- football_data %>%
|
||||||
|
select(2:5) %>% mutate(winner = apply(., 1, get_winner_name))
|
||||||
|
|
||||||
|
# Prepare data
|
||||||
|
home_teams <- football_data %>%
|
||||||
|
select("home_team") %>% unique()
|
||||||
|
|
||||||
|
away_teams <- football_data %>%
|
||||||
|
select("away_team") %>% unique()
|
||||||
|
|
||||||
|
# UI
|
||||||
|
ui <- fluidPage(
|
||||||
|
|
||||||
|
# Application title
|
||||||
|
titlePanel("International football results 1872-2018"),
|
||||||
|
|
||||||
|
# Sidebar with a slider input for number of bins
|
||||||
|
sidebarLayout(
|
||||||
|
sidebarPanel(
|
||||||
|
selectInput("first_team",
|
||||||
|
"First team:",
|
||||||
|
home_teams),
|
||||||
|
selectInput("second_team",
|
||||||
|
"Second team:",
|
||||||
|
away_teams)
|
||||||
|
),
|
||||||
|
|
||||||
|
# Show a plot of the generated distribution
|
||||||
|
mainPanel(
|
||||||
|
#plotOutput("balance"), TODO: balance plot (W:L:D)
|
||||||
|
DT::dataTableOutput("results_pagination")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Server logic
|
||||||
|
server <- function(input, output) {
|
||||||
|
#output$balance <- renderPlot()
|
||||||
|
output$results_pagination <- DT::renderDataTable(
|
||||||
|
get_matches_list(input$first_team, input$second_team),
|
||||||
|
extensions = 'Buttons',
|
||||||
|
options = list(
|
||||||
|
lengthMenu = list(c(5, 10, -1), c('5', '10', 'All')),
|
||||||
|
pageLength = 10,
|
||||||
|
searching = FALSE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the application
|
||||||
|
shinyApp(ui = ui, server = server)
|
||||||
|
|
0
.Rproj.user/812E148F/sources/s-83ED6DC2/lock_file
Normal file
0
.Rproj.user/812E148F/sources/s-83ED6DC2/lock_file
Normal file
3
.Rproj.user/E312DB19/console06/A6A56C55
Normal file
3
.Rproj.user/E312DB19/console06/A6A56C55
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[0m[0K]0;:/j/Desktop/TPD/ShinyAppExample[?25l
|
||||||
|
[0;32ms441472@term2 [0;35m [0;33m/j/Desktop/TPD/ShinyAppExample[0m[0K
|
||||||
|
$[0K[3G[?25h
|
1
.Rproj.user/E312DB19/console06/INDEX001
Normal file
1
.Rproj.user/E312DB19/console06/INDEX001
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"allow_restart":true,"alt_buffer":false,"autoclose":1,"buffered_output":"\n","caption":"Terminal 1","channel_id":"4555","channel_mode":1,"child_procs":false,"cols":60,"cwd":"","exit_code":15,"handle":"A6A56C55","interaction_mode":2,"max_output_lines":1000,"restarted":false,"rows":23,"shell_type":1,"show_on_output":false,"terminal_sequence":1,"title":":/j/Desktop/TPD/ShinyAppExample","track_env":false,"zombie":false}]
|
6
.Rproj.user/E312DB19/pcs/debug-breakpoints.pper
Normal file
6
.Rproj.user/E312DB19/pcs/debug-breakpoints.pper
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"debugBreakpointsState" : {
|
||||||
|
"breakpoints" : [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
9
.Rproj.user/E312DB19/pcs/files-pane.pper
Normal file
9
.Rproj.user/E312DB19/pcs/files-pane.pper
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"path" : "j:/Desktop/TPD/ShinyAppExample",
|
||||||
|
"sortOrder" : [
|
||||||
|
{
|
||||||
|
"ascending" : true,
|
||||||
|
"columnIndex" : 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
3
.Rproj.user/E312DB19/pcs/source-pane.pper
Normal file
3
.Rproj.user/E312DB19/pcs/source-pane.pper
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"activeTab" : 0
|
||||||
|
}
|
14
.Rproj.user/E312DB19/pcs/windowlayoutstate.pper
Normal file
14
.Rproj.user/E312DB19/pcs/windowlayoutstate.pper
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"left" : {
|
||||||
|
"panelheight" : 949,
|
||||||
|
"splitterpos" : 394,
|
||||||
|
"topwindowstate" : "NORMAL",
|
||||||
|
"windowheight" : 987
|
||||||
|
},
|
||||||
|
"right" : {
|
||||||
|
"panelheight" : 949,
|
||||||
|
"splitterpos" : 592,
|
||||||
|
"topwindowstate" : "NORMAL",
|
||||||
|
"windowheight" : 987
|
||||||
|
}
|
||||||
|
}
|
6
.Rproj.user/E312DB19/pcs/workbench-pane.pper
Normal file
6
.Rproj.user/E312DB19/pcs/workbench-pane.pper
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"TabSet1" : 0,
|
||||||
|
"TabSet2" : 0,
|
||||||
|
"TabZoom" : {
|
||||||
|
}
|
||||||
|
}
|
5
.Rproj.user/E312DB19/rmd-outputs
Normal file
5
.Rproj.user/E312DB19/rmd-outputs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
1
.Rproj.user/E312DB19/saved_source_markers
Normal file
1
.Rproj.user/E312DB19/saved_source_markers
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"active_set":"","sets":[]}
|
22
.Rproj.user/E312DB19/sources/per/t/A189941E
Normal file
22
.Rproj.user/E312DB19/sources/per/t/A189941E
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"collab_server" : "",
|
||||||
|
"contents" : "",
|
||||||
|
"created" : 1557778540402.000,
|
||||||
|
"dirty" : false,
|
||||||
|
"encoding" : "UTF-8",
|
||||||
|
"folds" : "",
|
||||||
|
"hash" : "2571298282",
|
||||||
|
"id" : "A189941E",
|
||||||
|
"lastKnownWriteTime" : 1557788269,
|
||||||
|
"last_content_update" : 1557788269529,
|
||||||
|
"path" : "j:/Desktop/TPD/ShinyAppExample/app.R",
|
||||||
|
"project_path" : "app.R",
|
||||||
|
"properties" : {
|
||||||
|
"cursorPosition" : "64,58",
|
||||||
|
"scrollLine" : "57"
|
||||||
|
},
|
||||||
|
"relative_order" : 1,
|
||||||
|
"source_on_save" : false,
|
||||||
|
"source_window" : "",
|
||||||
|
"type" : "r_source"
|
||||||
|
}
|
87
.Rproj.user/E312DB19/sources/per/t/A189941E-contents
Normal file
87
.Rproj.user/E312DB19/sources/per/t/A189941E-contents
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#
|
||||||
|
# This is a Shiny web application. You can run the application by clicking
|
||||||
|
# the 'Run App' button above.
|
||||||
|
#
|
||||||
|
# Find out more about building applications with Shiny here:
|
||||||
|
#
|
||||||
|
# http://shiny.rstudio.com/
|
||||||
|
#
|
||||||
|
|
||||||
|
library(shiny)
|
||||||
|
library(dplyr)
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
get_matches_list <- function(first_team, second_team) {
|
||||||
|
matches <- football_data %>%
|
||||||
|
select(1:9) %>%
|
||||||
|
filter(home_team %in% c(first_team, second_team)
|
||||||
|
& away_team %in% c(first_team, second_team))
|
||||||
|
return(matches)
|
||||||
|
}
|
||||||
|
|
||||||
|
get_winner_name <- function(match_row) {
|
||||||
|
if(match_row["home_score"] > match_row["away_score"]) {
|
||||||
|
return(match_row["home_team"])
|
||||||
|
}
|
||||||
|
else if(match_row["home_score"] < match_row["away_score"]) {
|
||||||
|
return(match_row["away_team"])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return("Draw")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load data
|
||||||
|
football_data <- as_tibble(read.csv("results.csv"))
|
||||||
|
football_data_ext <- football_data %>%
|
||||||
|
select(2:5) %>% mutate(winner = apply(., 1, get_winner_name))
|
||||||
|
|
||||||
|
# Prepare data
|
||||||
|
home_teams <- football_data %>%
|
||||||
|
select("home_team") %>% unique()
|
||||||
|
|
||||||
|
away_teams <- football_data %>%
|
||||||
|
select("away_team") %>% unique()
|
||||||
|
|
||||||
|
# UI
|
||||||
|
ui <- fluidPage(
|
||||||
|
|
||||||
|
# Application title
|
||||||
|
titlePanel("International football results 1872-2018"),
|
||||||
|
|
||||||
|
# Sidebar with a slider input for number of bins
|
||||||
|
sidebarLayout(
|
||||||
|
sidebarPanel(
|
||||||
|
selectInput("first_team",
|
||||||
|
"First team:",
|
||||||
|
home_teams),
|
||||||
|
selectInput("second_team",
|
||||||
|
"Second team:",
|
||||||
|
away_teams)
|
||||||
|
),
|
||||||
|
|
||||||
|
# Show a plot of the generated distribution
|
||||||
|
mainPanel(
|
||||||
|
#plotOutput("balance"), TODO: balance plot (W:L:D)
|
||||||
|
DT::dataTableOutput("results_pagination")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Server logic
|
||||||
|
server <- function(input, output) {
|
||||||
|
#output$balance <- renderPlot()
|
||||||
|
output$results_pagination <- DT::renderDataTable(
|
||||||
|
get_matches_list(input$first_team, input$second_team),
|
||||||
|
extensions = 'Buttons',
|
||||||
|
options = list(
|
||||||
|
lengthMenu = list(c(5, 10, -1), c('5', '10', 'All')),
|
||||||
|
pageLength = 10,
|
||||||
|
searching = FALSE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the application
|
||||||
|
shinyApp(ui = ui, server = server)
|
||||||
|
|
4
.Rproj.user/E312DB19/sources/prop/F0021F37
Normal file
4
.Rproj.user/E312DB19/sources/prop/F0021F37
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"cursorPosition" : "64,58",
|
||||||
|
"scrollLine" : "57"
|
||||||
|
}
|
1
.Rproj.user/E312DB19/sources/prop/INDEX
Normal file
1
.Rproj.user/E312DB19/sources/prop/INDEX
Normal file
@ -0,0 +1 @@
|
|||||||
|
j%3A%2FDesktop%2FTPD%2FShinyAppExample%2Fapp.R="F0021F37"
|
0
.Rproj.user/shared/notebooks/patch-chunk-names
Normal file
0
.Rproj.user/shared/notebooks/patch-chunk-names
Normal file
13
ShinyAppExample.Rproj
Normal file
13
ShinyAppExample.Rproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Version: 1.0
|
||||||
|
|
||||||
|
RestoreWorkspace: Default
|
||||||
|
SaveWorkspace: Default
|
||||||
|
AlwaysSaveHistory: Default
|
||||||
|
|
||||||
|
EnableCodeIndexing: Yes
|
||||||
|
UseSpacesForTab: Yes
|
||||||
|
NumSpacesForTab: 2
|
||||||
|
Encoding: UTF-8
|
||||||
|
|
||||||
|
RnwWeave: Sweave
|
||||||
|
LaTeX: pdfLaTeX
|
87
app.R
Normal file
87
app.R
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#
|
||||||
|
# This is a Shiny web application. You can run the application by clicking
|
||||||
|
# the 'Run App' button above.
|
||||||
|
#
|
||||||
|
# Find out more about building applications with Shiny here:
|
||||||
|
#
|
||||||
|
# http://shiny.rstudio.com/
|
||||||
|
#
|
||||||
|
|
||||||
|
library(shiny)
|
||||||
|
library(dplyr)
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
get_matches_list <- function(first_team, second_team) {
|
||||||
|
matches <- football_data %>%
|
||||||
|
select(1:9) %>%
|
||||||
|
filter(home_team %in% c(first_team, second_team)
|
||||||
|
& away_team %in% c(first_team, second_team))
|
||||||
|
return(matches)
|
||||||
|
}
|
||||||
|
|
||||||
|
get_winner_name <- function(match_row) {
|
||||||
|
if(match_row["home_score"] > match_row["away_score"]) {
|
||||||
|
return(match_row["home_team"])
|
||||||
|
}
|
||||||
|
else if(match_row["home_score"] < match_row["away_score"]) {
|
||||||
|
return(match_row["away_team"])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return("Draw")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load data
|
||||||
|
football_data <- as_tibble(read.csv("results.csv"))
|
||||||
|
football_data_ext <- football_data %>%
|
||||||
|
select(2:5) %>% mutate(winner = apply(., 1, get_winner_name))
|
||||||
|
|
||||||
|
# Prepare data
|
||||||
|
home_teams <- football_data %>%
|
||||||
|
select("home_team") %>% unique()
|
||||||
|
|
||||||
|
away_teams <- football_data %>%
|
||||||
|
select("away_team") %>% unique()
|
||||||
|
|
||||||
|
# UI
|
||||||
|
ui <- fluidPage(
|
||||||
|
|
||||||
|
# Application title
|
||||||
|
titlePanel("International football results 1872-2018"),
|
||||||
|
|
||||||
|
# Sidebar with a slider input for number of bins
|
||||||
|
sidebarLayout(
|
||||||
|
sidebarPanel(
|
||||||
|
selectInput("first_team",
|
||||||
|
"First team:",
|
||||||
|
home_teams),
|
||||||
|
selectInput("second_team",
|
||||||
|
"Second team:",
|
||||||
|
away_teams)
|
||||||
|
),
|
||||||
|
|
||||||
|
# Show a plot of the generated distribution
|
||||||
|
mainPanel(
|
||||||
|
#plotOutput("balance"), TODO: balance plot (W:L:D)
|
||||||
|
DT::dataTableOutput("results_pagination")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Server logic
|
||||||
|
server <- function(input, output) {
|
||||||
|
#output$balance <- renderPlot()
|
||||||
|
output$results_pagination <- DT::renderDataTable(
|
||||||
|
get_matches_list(input$first_team, input$second_team),
|
||||||
|
extensions = 'Buttons',
|
||||||
|
options = list(
|
||||||
|
lengthMenu = list(c(5, 10, -1), c('5', '10', 'All')),
|
||||||
|
pageLength = 10,
|
||||||
|
searching = FALSE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run the application
|
||||||
|
shinyApp(ui = ui, server = server)
|
||||||
|
|
39673
results.csv
Normal file
39673
results.csv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user