Skip to content

Instantly share code, notes, and snippets.

@pssguy
Created November 16, 2012 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pssguy/4082826 to your computer and use it in GitHub Desktop.
Save pssguy/4082826 to your computer and use it in GitHub Desktop.
Shiny App showing graphs of goal methods for all EPL players with more than 50 career goals
# My first tiny-shiny
# Thanks to all the guys at R-Studio, especially Joe Cheng for some hand-holding
# The global.r script can hold variables available to both ui.r and server.R
library(shiny)
library(ggplot2)
# data based on goals scored to early November 2012
df <- read.csv("http://www.premiersoccerstats.com/shinyGoals.csv",stringsAsFactors=FALSE)
# create the data
playerChoices <- unique(df[,c(2,3)])$PLAYERID
names(playerChoices) <- unique(df[,c(2,3)])$name
shinyServer(function(input, output) {
output$myPlot <- reactivePlot(function(var=input$var,player=input$player) {
myData <- subset(df,(option==var)&PLAYERID==player)
q <-ggplot(data=myData,aes(x=Season,y=Goals,fill=variable))+ geom_bar(stat="identity") + guides(fill=guide_legend(title=NULL))
print(q)
})
# Adjust caption text to reflect goal information requested
output$caption <- reactiveText(function() {
paste0(" Goals By ",input$var)
})
})
# goal type by top scorers
shinyUI(pageWithSidebar(
# Application title
headerPanel("PremierSoccerStats"),
# Sidebar with controls to select the player and goal variable
sidebarPanel(
helpText(
"Choose any of the 79 players with
50 or more goals in the EPL and
see their goals by season according
to selected criteria"),
helpText(
"After initial loading of the data,
changes are instantaneous"),
selectInput("var", "Select a Variable:",
list("Method" = "Method",
"Play" = "Play",
"Place" = "Place",
"Venue" = "Venue",
"Time" = "Time"
)),
selectInput("player", "Player:",playerChoices,selected="Wayne Rooney")
),
# Show the caption and stacked bar plot of the requested variable
mainPanel(
h3(textOutput("caption")),
plotOutput("myPlot")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment