Skip to content

Commit 77fbc02

Browse files
committed
removed world cup code from blog post
1 parent aed1661 commit 77fbc02

File tree

1 file changed

+0
-134
lines changed

1 file changed

+0
-134
lines changed

_posts/2014-6-19-worldcup2014.md

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -24,137 +24,3 @@ Initially, the app loads scoring related data for all participating teams.
2424
It is possible to view data related to specific team, by simply selecting a team in the dropdown. It is also possible to monitor other metrics by selecting the desired one in the Metric dropdown.
2525

2626
The data table is reactive and refreshes automatically.
27-
28-
{% highlight R linenos %}
29-
30-
31-
library(shiny)
32-
library(XML)
33-
scrape2014 <- function(url) {
34-
doc <- htmlParse(url)
35-
temp<-getNodeSet(doc, "/*//span[@class=\"sorted-icon-wrap\"]")
36-
removeNodes(temp)
37-
38-
var_names <- sapply(getNodeSet(doc, "//th"),
39-
xmlGetAttr, "class")
40-
var_names <- gsub(" playername-nolink", "", gsub("tbl-", "", var_names))
41-
tables <- readHTMLTable(doc)
42-
tab <- tables[[1]]
43-
44-
var_teams <- sapply(getNodeSet(doc, "//td/span/img[@class='flag']"),
45-
xmlGetAttr, "src")
46-
tab$flag = paste("<img src=\"",var_teams,"\" />")
47-
tab$team = toupper(gsub(".png", "", gsub("http://img.fifa.com/images/flags/3/", "", var_teams)))
48-
colnames(tab) <- c(var_names, "flag", "team")
49-
tab <- tab[c("flag", "team", var_names)]
50-
return(tab)
51-
}
52-
53-
bind2014 <- function(p) {
54-
url <- switch(
55-
p,
56-
'gs' = "http://www.fifa.com/worldcup/statistics/players/goal-scored.html",
57-
's' = "http://www.fifa.com/worldcup/statistics/players/shots.html",
58-
'sp' = "http://www.fifa.com/worldcup/statistics/players/shots-positions.html",
59-
'a' = "http://www.fifa.com/worldcup/statistics/players/attacking.html",
60-
'de' = "http://www.fifa.com/worldcup/statistics/players/defending.html",
61-
'di' = "http://www.fifa.com/worldcup/statistics/players/disciplinary.html",
62-
'p' = "http://www.fifa.com/worldcup/statistics/players/passes.html",
63-
'dis' = "http://www.fifa.com/worldcup/statistics/players/distance.html"
64-
)
65-
66-
try <- scrape2014(url)
67-
for (i in 4:ncol(try)) { try[,i] <- as.numeric(as.character(try[,i]))}
68-
nms <- switch(
69-
p,
70-
'gs' = c("F", "TEAM", "PLAYER", "MATCHES PLAYED", "MINUTES PLAYED",
71-
"TOTAL GOALS SCORED", "ASSISTS", "PENALTIES SCORED",
72-
"GOALS SCORED WITH THE LEFT FOOT", "GOALS SCORED WITH THE RIGHT FOOT",
73-
"HEADED GOALS"),
74-
's' = c("F", "TEAM", "PLAYER", "MATCHES PLAYED", "MINUTES PLAYED",
75-
"SHOTS", "ATTEMPTS ON TARGET", "ATTEMPTS OFF-TARGET", "WOODWORK"),
76-
'sp' = c("F", "TEAM", "PLAYER", "MATCHES PLAYED", "MINUTES PLAYED",
77-
"ATTEMPTS", "ATTEMPTS ON TARGET", "ATTEMPTS IN THE AREA",
78-
"ATTEMPTS OUTSIDE THE AREA", "ATTEMPTS ON-TARGET FROM INSIDE THE AREA",
79-
"ATTEMPTS ON-TARGET FROM OUTSIDE THE AREA"),
80-
'a' = c("F", "TEAM", "PLAYER", "MATCHES PLAYED", "MINUTES PLAYED",
81-
"TOTAL GOALS SCORED", "OFFSIDES", "SOLO RUNS INTO AREA",
82-
"LOST BALLS", "DELIVERIES IN PENALTY AREA", "TACKLES",
83-
"TACKLES SUFFERED"),
84-
'de' = c("F", "TEAM", "PLAYER", "MATCHES PLAYED", "MINUTES PLAYED",
85-
"TACKLES", "TACKLES WON", "ATTEMPTED CLEARANCES", "CLEARANCE RATE",
86-
"SAVES", "BLOCKS", "RECOVERED BALLS"),
87-
'di' = c("F", "TEAM", "PLAYER", "MATCHES PLAYED", "YELLOW CARDS",
88-
"SECOND YELLOW CARD AND RED CARD", "RED CARDS", "FOULS COMMITTED",
89-
"FOULS SUFFERED", "FOULS CAUSING A PENALTY"),
90-
'p' = c("F", "TEAM", "PLAYER", "MATCHES PLAYED", "MINUTES PLAYED",
91-
"TOTAL PASSES", "PASSES COMPLETED", "PASSES COMPLETED (%)",
92-
"CROSSES", "CROSSES COMPLETED", "CROSSES COMPLETED (%)", "CORNERS",
93-
"THROW-INS", "THROW-INS COMPLETED"),
94-
'dis' = c("F", "TEAM", "PLAYER", "MATCHES PLAYED", "MINUTES PLAYED",
95-
"DISTANCE COVERED", "DISTANCE COVERED IN POSSESSION",
96-
"DISTANCE COVERED NOT IN POSSESSION", "TOP SPEED")
97-
)
98-
names(try) <- nms
99-
return(try)
100-
}
101-
102-
shinyServer(function(input, output) {
103-
104-
plrs <- reactive({
105-
players <- bind2014(input$metric)
106-
if (input$team != "*") {
107-
players <- subset(players, TEAM == input$team)
108-
}
109-
return(players)
110-
})
111-
112-
tms <- reactive({
113-
t <- plrs()
114-
t[3] <- NULL
115-
t[,2] <- paste(t[,1], t[,2], sep="&nbsp;")
116-
t[1] <- NULL
117-
return(aggregate(. ~ TEAM, data = t, FUN = sum))
118-
})
119-
120-
url <- reactive({
121-
switch (input$metric,
122-
'gs' = "http://www.fifa.com/worldcup/statistics/players/goal-scored.html",
123-
's' = "http://www.fifa.com/worldcup/statistics/players/shots.html",
124-
'sp' = "http://www.fifa.com/worldcup/statistics/players/shots-positions.html",
125-
'a' = "http://www.fifa.com/worldcup/statistics/players/attacking.html",
126-
'de' = "http://www.fifa.com/worldcup/statistics/players/defending.html",
127-
'di' = "http://www.fifa.com/worldcup/statistics/players/disciplinary.html",
128-
'p' = "http://www.fifa.com/worldcup/statistics/players/passes.html",
129-
'dis' = "http://www.fifa.com/worldcup/statistics/players/distance.html"
130-
)
131-
})
132-
133-
output$topScorers <- renderDataTable({
134-
plrs()
135-
})
136-
137-
output$teamStats <- renderDataTable({
138-
tms()
139-
})
140-
141-
output$selMetric <- renderText({
142-
switch (input$metric,
143-
'gs' = "Goals Scored",
144-
's' = "Shots",
145-
'sp' = "Shots positions",
146-
'a' = "Attacking",
147-
'de' = "Defending",
148-
'di' = "Disciplinary",
149-
'p' = "Passes",
150-
'dis' = "Distance"
151-
)
152-
})
153-
154-
output$selUrl <- renderText({
155-
url()
156-
})
157-
158-
})
159-
160-
{% endhighlight %}

0 commit comments

Comments
 (0)