Analyzing Local Data with a Shiny Web App
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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
- The raw data in a gVis Table, which allows sorting and paging
- A density graph with the spread of results by term and year
- A statistical test to see if there is a difference in marks by gender
#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
# server.R shinyServer(function(input, output) { Data |
Finally, global.R loads the requisite libraries and houses the script which generated the sample file
#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 (626)
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.