# UI for application
ui <- fluidPage(
theme = shinytheme("sandstone"),
titlePanel(h1("Compare FIFA Professional Football Players", align = "center", style = "color : #D6BD86"), windowTitle = "Fifa Comparisons"),
tags$style(HTML("
.tabbable > .nav > li > a {background-color: #0B5279; color:#D6BD86}
.tabbable > .nav > li[class=active] > a {background-color: #1D3468; color:#D6BD86}
.item { #background: #0B5279 !important; #color: #D6BD86 !important;}
.selectize-dropdown-content .active {background: #1D3468 !important; color: #D6BD86 !important;}
body {background-color: #7aaad6;}
")),
tabsetPanel(
tabPanel("Abstract",
hr(),
h3(strong("What's the point?")),
p("This app allows users to compare professional football players registered in FIFA based on various attributes."),
hr(),
h3(strong("About FIFA")),
p("FIFA (Fédération Internationale de Football Association) is the international governing body for the sport of soccer (football). Founded in 1904 and headquartered in Zurich, Switzerland, FIFA is responsible for organizing and overseeing major international soccer tournaments, including the FIFA World Cup, which is held every four years and is one of the most widely viewed sporting events globally. FIFA sets the rules of the game, promotes fair play, and fosters the development of soccer worldwide."),
hr(),
h3(strong("About the dataset")),
h4("Source"),
p("The dataset comes from Kaggle and was created by", a(href="https://www.kaggle.com/maso0dahmed", "Masood Ahmed.")),
p("You can find the dataset here:", a(href="https://www.kaggle.com/datasets/maso0dahmed/football-players-data?resource=download", "Kaggle 'Football Players Data.'")),
h4("Content"),
p("This dataset contains detailed attributes for every player registered in FIFA database.",
"The data has been scraped from the website", a(href="https://sofifa.com/", "sofifa"),
),
p("- 17k+ FIFA players"),
p("- ~50 attributes extracted from the latest FIFA database"),
h4("Inspiration"),
p("The inspiration behind selecting this dataset stems from a passion for football and a desire to explore the vast array of attributes defining professional players. With over 17,000 FIFA-registered players and comprehensive data scraped from sofifa.com, this dataset provides a rich resource for analyzing player performance, demographics, and market values, offering valuable insights into the world of football."),
hr()
),
tabPanel("About the Dataset",
tableOutput("dataset_summary_table"),
plotOutput("age_histogram"),
plotOutput("top_10_wages_by_nationality"),
plotOutput("worst_10_wages_by_nationality"),
),
tabPanel("Compare Players",
titlePanel("Select Players to Compare"),
p("Use the search box below to find and select players to compare their attributes."),
sidebarLayout(
sidebarPanel(
selectizeInput(inputId = 'name', label = 'Search Players', choices = fifa_players$full_name,
selected = "Cristiano Ronaldo", multiple = TRUE, options = list(create = FALSE))),
mainPanel(
tabsetPanel(
tabPanel("Description", tableOutput("table1")),
tabPanel("Viz",
selectInput("att", "Choose a variable to compare:",
choices = c("age", "height_cm", "weight_kgs", "overall_rating", "international_reputation.1.5.", "wage_euro", "value_euro")),
plotOutput("plot"))
)))),
tabPanel("Filter by Attribute",
titlePanel("Filter Players by Attribute"),
p("Choose an attribute to filter players."),
mainPanel(
tabsetPanel(
tabPanel("Overall Rating",
sliderInput("overall", "Choose an Overall Rating:", min = 0, max = 100, value = c(70, 100)),
tableOutput("tableOverall")),
tabPanel("Age",
sliderInput("age", "Choose an Age:", min = 15, max = 45, value = c(20, 35)),
tableOutput("tableAge")),
tabPanel("Positions",
selectInput("positions", "Choose a Position:", choices = unique(fifa_players$positions), selected = NULL),
tableOutput("tablePositions")),
tabPanel("Nationality",
selectInput("nationality", "Choose a Nationality:", choices = unique(fifa_players$nationality), selected = NULL),
tableOutput("tableNationality"))
)))))
## Warning: The select input "name" contains a large number of options; consider
## using server-side selectize for massively improved performance. See the Details
## section of the ?selectizeInput help topic.
# Server logic
server <- function(input, output) {
# Summary of the dataset
dataset_summary <- reactive({
head(fifa_players, 10)
})
# Render the dataset summary table
output$dataset_summary_table <- renderTable({
dataset_summary()
})
# Generate histogram of fifa_players ages
output$age_histogram <- renderPlot({
ggplot(fifa_players, aes(x = age)) +
geom_histogram(binwidth = 1, fill = "#003366", color = "#add8e6") +
labs(title = "Histogram of Player Ages", x = "Age", y = "Frequency") +
theme_economist()
})
# Plot for the most represented nationalities
output$top_nationalities <- renderPlot({
top_nationalities <- names(sort(table(fifa_players$nationality), decreasing = TRUE)[1:10])
top_10_data <- fifa_players[fifa_players$nationality %in% top_nationalities, ]
ggplot(top_10_data, aes(x = nationality)) +
geom_bar(stat = "identity", fill = "#003366", color = "#add8e6") +
labs(x = "Nationality", y = "Frequency", title = "Top 10 Most Represented Nationalities") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
})
# Plot for the top 10 wages by nationality
output$top_10_wages_by_nationality <- renderPlot({
top_10_wages <- fifa_players %>%
group_by(nationality) %>%
summarise(avg_wage = max(wage_euro)) %>%
top_n(10, avg_wage)
ggplot(top_10_wages, aes(y = reorder(nationality, avg_wage), x = avg_wage)) +
geom_bar(stat = "identity", fill = "#003366", color = "#add8e6") +
labs(title = "Top 10 Average Wages by Nationality", y = "Nationality", x = "Average Wage (Euro)") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
scale_x_continuous(labels = comma)
})
# Plot for the worst 10 wages by nationality
output$worst_10_wages_by_nationality <- renderPlot({
worst_10_wages <- fifa_players %>%
group_by(nationality) %>%
summarise(min_wage = min(wage_euro)) %>%
bottom_n(10, min_wage)
ggplot(worst_10_wages, aes(x = reorder(nationality, min_wage), y = min_wage)) +
geom_bar(stat = "identity", fill = "#003366", color = "#add8e6") +
labs(title = "Worst 10 Average Wages by Nationality", x = "Nationality", y = "Average Wage (Euro)") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
scale_y_continuous(labels = comma_format())
})
# Compare Players
fifa_subset <- reactive({
filter(fifa_players, full_name %in% input$name)
})
output$table1 <- renderTable({
xtable(fifa_subset())
})
# Compare Players Plot
output$plot <- renderPlot({
ggplot(fifa_subset(), aes_string(x = "full_name", y = input$att)) +
theme_economist() +
geom_bar(stat = "identity", fill = '#003366', color = '#add8e6') +
geom_text(aes(label = ..y..), vjust = -0.5, size = 8, color = '#D6BD86')
})
# Filter Players by Overall Rating
output$tableOverall <- renderTable({
filtered_players <- filter(fifa_players, overall_rating >= input$overall[1] & overall_rating <= input$overall[2])
xtable(filtered_players)
})
# Filter Players by Age
output$tableAge <- renderTable({
filtered_players <- filter(fifa_players, age >= input$age[1] & age <= input$age[2])
xtable(filtered_players)
})
# Filter Players by Position
output$tablePositions <- renderTable({
filtered_players <- filter(fifa_players, positions == input$positions)
xtable(filtered_players)
})
# Filter Players by Nationality
output$tableNationality <- renderTable({
filtered_players <- filter(fifa_players, nationality == input$nationality)
xtable(filtered_players)
})
}
# Run the application
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents