public
Last active

Quick example of a Shiny app for explorer a dump of Guardian 2014 university rankings data

  • Download Gist
global.R
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#Here's a way of grabbing down the data - it probably makes sense to grab a local copy...
library(RCurl)
gsqAPI = function(key,query,gid=0){
tmp=getURL( paste( sep="",'https://spreadsheets.google.com/tq?', 'tqx=out:csv','&tq=', curlEscape(query), '&key=', key, '&gid=', gid), ssl.verifypeer = FALSE )
return( read.csv( textConnection( tmp ), stringsAsFactors=F ) )
}
 
handler=function(key,i){
tmp=gsqAPI(key,"select * where B!=''", i)
subject=sub(".Rank",'',colnames(tmp)[1])
colnames(tmp)[1]="Subject.Rank"
tmp$subject=subject
tmp
}
 
key='0Aq73qj3QslDedHFNdUsxOVZQZ1dmbXNrYlZGUWgwdHc'
gdata=handler(key,2)
 
for (i in 3:47){
gdata=rbind(gdata,handler(key,i))
}
 
#save(gdata,file="guardian2014unidata.Rda")
#Or just load the data in if you have saved it previously...
#load("guardian2014unidata.Rda")
 
gdata[, 4:11] <- sapply(gdata[, 4:11], as.numeric)
gdata$Name.of.Institution=as.factor(gdata$Name.of.Institution)
gdata$subject=as.factor(gdata$subject)
server.R
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
library(shiny)
library(ggplot2)
 
# Define server logic
shinyServer(function(input, output) {
#Simple test plot
output$testPlot = renderPlot( {
pdata=subset(gdata, Name.of.Institution==input$tbl)
#g=ggplot(pdata) + geom_text(aes(x=X..Satisfied.with.Teaching,y=X..Satisfied.with.Assessment,label=subject,size=Value.added.score.10))
g=ggplot(pdata) + geom_text(aes_string(x=input$tblx,y=input$tbly,size=input$tbls, label='subject'))
g=g+labs(title=paste("Guardian University Tables 2014:",input$tbl))
print(g)
})
})
ui.R
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
library(shiny)
 
uList=levels(gdata$Name.of.Institution)
names(uList) = uList
 
cList=colnames(gdata[c(1,3:11)])
names(cList) = cList
 
# Define UI for application that plots random distributions
shinyUI(pageWithSidebar(
# Application title
headerPanel("Guardian 2014 University Tables Explorer"),
sidebarPanel(
#Just a single selector here - which table do you want to view?
selectInput("tbl", "Institution:",uList),
selectInput("tblx", "x axis:",cList,selected = 'X..Satisfied.with.Teaching'),
selectInput("tbly", "y axis:",cList,selected='X..Satisfied.with.Assessment'),
selectInput("tbls", "Label size:",cList,selected = 'Value.added.score.10'),
div("This demo provides a crude graphical view over data extracted from",
a(href='http://www.guardian.co.uk/news/datablog/2013/jun/04/university-guide-2014-table-rankings',
"Guardian Datablog: University guide 2014 data tables") )
),
#The main panel is where the "results" charts are plotted
mainPanel(
plotOutput("testPlot")#,
#tableOutput("view")
)
))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.