Monthly Archives: March 2013

Analyzing Local Data with a Shiny Web App

A great. recent enhancement for the Shiny App is the ability to upload local files.
Now, in addition to users being able to interact with data provided on the host e.g.
Soccer Tables or via the web, Wikipedia Search Rates they can use apps
to view and analyse their own data

I have knocked up an app based on the 09_upload example provided in the Shiny package. It uploads a small .csv spreadsheet file of school pupil’s scores from a local directory, displays the data and does a couple of analyses.

The ui.R  enables a user to upload a csv file with various parameters, seperator etc.  The example file is downloadable. There are then three tabs showing

  1. The raw data in a gVis Table, which allows sorting and paging
  2. A density graph with the spread of results by term and year
  3. A statistical test to see if there is a difference in marks by gender
?View Code RSPLUS
#ui.R
shinyUI(pageWithSidebar(
  headerPanel("Uploaded File Analysis"),
 
  sidebarPanel(
    helpText("This app is shows how a user can update a csv file from their own hard drive for instant analysis.
In the default case, it uses standard format school marks that could be used by many teachers
Any file can be uploaded but analysis is only available
if the data is in same format as the sample file, downloadable below
"),
    a("Pupil Marks", href="http://dl.dropbox.com/u/25945599/scores.csv"),
    tags$hr(),
    fileInput('file1', 'Choose CSV File from local drive, adjusting parameters if necessary',
              accept=c('text/csv', 'text/comma-separated-values,text/plain')),
 
    checkboxInput('header', 'Header', TRUE),
    radioButtons('sep', 'Separator',
                 c(Comma=',',
                   Semicolon=';',
                   Tab='\t'),
                 'Comma'),
    radioButtons('quote', 'Quote',
                 c(None='',
                   'Double Quote'='"',
                   'Single Quote'="'"),
                 'Double Quote'),
    tags$head(tags$style(type="text/css",
                         "label.radio { display: inline-block; margin:0 10 0 0;  }",
                         ".radio input[type=\"radio\"] { float: none; }"))
 
  ),
  mainPanel(
    tabsetPanel(
      tabPanel("Pupil Marks",
               h4(textOutput("caption1")),
               checkboxInput(inputId = "pageable", label = "Pageable"),
               conditionalPanel("input.pageable==true",
                                numericInput(inputId = "pagesize",
                                             label = "Pupils per page",value=13,min=1,max=25)),
 
               htmlOutput("raw"),
                value = 1),
      tabPanel("Term Details",
               h4(textOutput("caption2")),
               plotOutput("density"),
               htmlOutput("notes2"),
               value = 2),
      tabPanel("Gender difference",
               h4(textOutput("caption3")),
               plotOutput("genderDensity", height="250px"),
               verbatimTextOutput("sexDiff"),
               htmlOutput("notes3"),
               value = 3),
      id="tabs1")
 
)
))

The server.R takes the file, does some processing and provides a list of data which can be rendered into plots and tables

?View Code RSPLUS
# server.R
shinyServer(function(input, output) {
 
  Data

Finally, global.R loads the requisite libraries and houses the script which generated the sample file

?View Code RSPLUS
#global.R
# load required libraries
library(shiny)
library(plyr)
library(ggplot2)
library(googleVis)
library(reshape2)
 
####creation of example data on local directory for uploading####
 
# #load a list of common first names
# faveNames

The app is viewable on glimmer and the code as a gist

Rooney as Fall Guy

The press is awash with rumours that Wayne Rooney and his massive salary are out of Old Trafford this summer, provided there are takers at 20 million
His failure to make the starting lineup for the game against Real Madrid and whispers of poor training practices and conditioning only fuel the speculation

However, I am wondering if he is taking the heat for a poor decision not to start him over Danny Welbeck, a player who has just one goal in twenty league appearances this season and who missed a couple of opportunities in the game which would have put United into the lead.

Rooney’s stats on the face of it show no decline in ability. He has been very consistent over the years, more of a provider with Ronaldo or van Persie in the team but stepping up his goalscoring in their absence. Indeed, taking into account the time he has spent on the pitch, this season he has been as good as ever as an attacking force in the league
Apologies for graph but red is goals, assists is green and y axis is per game-equivalent

Over his career, Rooney matches up very well with the all-time EPL greats

Of the leading current players, he is by far the youngest. Already, sixth on the all-time EPL scoring list and ninth in assists, he has every chance to become the most prolific player in EPL history by the end of his career. However, there are some warning signs. Although he has eleven leaue goals this season, only two have been winners compared with nine last year and a best of ten two years prior. In addition, although, at 27, he should still be in his prime his first appearance was more than a decade ago and wear and tear do appear to have affected his physical abilities.

So where might he end up? He doesn’t strike me as an obvious candidate to move abroad. Spurs might be the best bet as they have question marks over several front players in Bale(potential massive transfer), Defoe(age/injuries) an Adebayor(poor value for money)