Initial commit

This commit is contained in:
s441472 2019-05-14 22:41:05 +02:00
commit c17dfb82d7
24 changed files with 40202 additions and 0 deletions

BIN
.RData Normal file

Binary file not shown.

157
.Rhistory Normal file
View 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()

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1 @@
j%3A%2FDesktop%2FTPD%2FShinyAppExample%2Fapp.R="AF44A8"

View 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"
}

View 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)

View File

@ -0,0 +1,3 @@
]0;:/j/Desktop/TPD/ShinyAppExample[?25l
s441472@term2  /j/Desktop/TPD/ShinyAppExample
$[?25h

View 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}]

View File

@ -0,0 +1,6 @@
{
"debugBreakpointsState" : {
"breakpoints" : [
]
}
}

View File

@ -0,0 +1,9 @@
{
"path" : "j:/Desktop/TPD/ShinyAppExample",
"sortOrder" : [
{
"ascending" : true,
"columnIndex" : 2
}
]
}

View File

@ -0,0 +1,3 @@
{
"activeTab" : 0
}

View File

@ -0,0 +1,14 @@
{
"left" : {
"panelheight" : 949,
"splitterpos" : 394,
"topwindowstate" : "NORMAL",
"windowheight" : 987
},
"right" : {
"panelheight" : 949,
"splitterpos" : 592,
"topwindowstate" : "NORMAL",
"windowheight" : 987
}
}

View File

@ -0,0 +1,6 @@
{
"TabSet1" : 0,
"TabSet2" : 0,
"TabZoom" : {
}
}

View File

@ -0,0 +1,5 @@

View File

@ -0,0 +1 @@
{"active_set":"","sets":[]}

View 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"
}

View 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)

View File

@ -0,0 +1,4 @@
{
"cursorPosition" : "64,58",
"scrollLine" : "57"
}

View File

@ -0,0 +1 @@
j%3A%2FDesktop%2FTPD%2FShinyAppExample%2Fapp.R="F0021F37"

13
ShinyAppExample.Rproj Normal file
View 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
View 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

File diff suppressed because it is too large Load Diff