Created
November 16, 2012 00:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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