<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>OUseful.Info, the blog... &#187; Quick Shiny Demo &#8211; Exploring NHS Winter Sit Rep Data</title>
	<atom:link href="http://blog.ouseful.info/2012/11/28/quick-shiny-demo-exploring-nhs-winter-sit-rep-data/feed/?withoutcomments=1" rel="self" type="application/rss+xml" />
	<link>http://blog.ouseful.info</link>
	<description>Trying to find useful things to do with emerging technologies in open education</description>
	<lastBuildDate>Fri, 24 May 2013 07:08:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.ouseful.info' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>OUseful.Info, the blog... &#187; Quick Shiny Demo &#8211; Exploring NHS Winter Sit Rep Data</title>
		<link>http://blog.ouseful.info</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.ouseful.info/osd.xml" title="OUseful.Info, the blog..." />
	<atom:link rel='hub' href='http://blog.ouseful.info/?pushpress=hub'/>
		<item>
		<title>Quick Shiny Demo &#8211; Exploring NHS Winter Sit Rep Data</title>
		<link>http://blog.ouseful.info/2012/11/28/quick-shiny-demo-exploring-nhs-winter-sit-rep-data/</link>
		<comments>http://blog.ouseful.info/2012/11/28/quick-shiny-demo-exploring-nhs-winter-sit-rep-data/#comments</comments>
		<pubDate>Wed, 28 Nov 2012 10:32:19 +0000</pubDate>
		<dc:creator>Tony Hirst</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[Infoskills]]></category>
		<category><![CDATA[Rstats]]></category>
		<category><![CDATA[Rstudio]]></category>
		<category><![CDATA[Shiny]]></category>

		<guid isPermaLink="false">http://blog.ouseful.info/?p=9127</guid>
		<description><![CDATA[Having spent a chink of the weekend and a piece of yesterday trying to pull NHS Winter sitrep data into some sort of shape in Scraperwiki, (described, in part, here: When Machine Readable Data Still Causes “Issues” – Wrangling Dates…), I couldn&#8217;t but help myself last night and had a quick go at using RStudio&#8217;s [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=9127&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Having spent a chink of the weekend and a piece of yesterday trying to pull NHS Winter sitrep data into some sort of shape in Scraperwiki, (described, in part, here: <a href="http://blog.ouseful.info/2012/11/27/when-machine-readable-data-still-causes-issues-wrangling-dates/">When Machine Readable Data Still Causes “Issues” – Wrangling Dates…</a>), I couldn&#8217;t but help myself last night and had a quick go at using RStudio&#8217;s <a href="http://rstudio.github.com/shiny/tutorial/">Shiny</a> tooling to put together a quick, minimal explorer for it:</p>
<p><a href="http://glimmer.rstudio.com/psychemedia/wightsitrep2/"><img src="http://ouseful.files.wordpress.com/2012/11/wight-sit-reps.png?w=700&#038;h=458" alt="" title="wight sit reps" width="700" height="458" class="alignnone size-full wp-image-9128" /></a></p>
<p>For proof of concept, I just pulled in data relating to the Isle of Wight NHS Trust, but it should be possible to build a more generic explorer: <a href="http://glimmer.rstudio.com/psychemedia/wightsitrep2/">Isle of Wight NHS Sit Rep Explorer Demo</a>.</p>
<p>Three files are used to crate the app &#8211; a script to define the user interface (ui.R), a script to define the server that responds to UI actions and displays the charts (server.R), and a supporting file that creates variables and functions that are globally available to bother the server and UI scripts (global.R).</p>
<pre class="brush: r; title: ; notranslate">##wightsitrep2/global.R

#Loading in CSV directly from https seems to cause problems but this workaround seems okay
floader=function(fn){
  temporaryFile &lt;- tempfile()
  download.file(fn,destfile=temporaryFile, method=&quot;curl&quot;)
  read.csv(temporaryFile)
}

#This is the data source - a scraperwiki API call
#It would make sense to abstract this further, eg allowing the creation of the URL based around a passed in a select statement
u=&quot;https://api.scraperwiki.com/api/1.0/datastore/sqlite?format=csv&amp;name=nhs_sit_reps&amp;query=select%20SHA%2CName%2C%20fromDateStr%2CtoDateStr%2C%20tableName%2CfacetB%2Cvalue%20from%20fulltable%20%20where%20Name%20like%20'%25WIGH%25'&quot;

#Load the data and do a bit typecasting, just in case...
d=floader(u)
d$fdate=as.Date(d$fromDateStr)
d$tdate=as.Date(d$toDateStr)
d$val=as.integer(d$value)</pre>
<pre class="brush: r; title: ; notranslate">##wightsitrep2/ui.R

library(shiny)

tList=levels(d$tableName)
names(tList) = tList

# Define UI for application that plots random distributions 
shinyUI(pageWithSidebar(
  
  
  # Application title
  headerPanel(&quot;IW NHS Trust Sit Rep Explorer&quot;),
  
  sidebarPanel(
    #Just a single selector here - which table do you want to view?
    selectInput(&quot;tbl&quot;, &quot;Report:&quot;,tList),
    
    div(&quot;This demo provides a crude graphical view over data extracted from&quot;,
        a(href='http://transparency.dh.gov.uk/2012/10/26/winter-pressures-daily-situation-reports-2012-13/',
          &quot;NHS Winter pressures daily situation reports&quot;),
        &quot;relating to the Isle of Wight NHS Trust.&quot;),
    div(&quot;The data is pulled in from a scraped version of the data stored on Scraperwiki&quot;,
        a(href=&quot;https://scraperwiki.com/scrapers/nhs_sit_reps/&quot;,&quot;NHS Sit Reps&quot;),&quot;.&quot;)
    
 ),
  
  #The main panel is where the &quot;results&quot; charts are plotted
  mainPanel(
    plotOutput(&quot;testPlot&quot;),
    tableOutput(&quot;view&quot;)
    
  )
))</pre>
<pre class="brush: r; title: ; notranslate">##wightsitrep2/server.R

library(shiny)
library(ggplot2)

# Define server logic
shinyServer(function(input, output) {
  
  #Do a simple barchart of data in the selected table.
  #Where there are &quot;subtables&quot;, display these using the faceted view
  output$testPlot = reactivePlot(function() {
    g=ggplot(subset(d,fdate&gt;as.Date('2012-11-01') &amp; tableName==input$tbl))
    g=g+geom_bar(aes(x=fdate,y=val),stat='identity')+facet_wrap(~tableName+facetB)
    g=g+theme(axis.text.x=element_text(angle=-90),legend.position=&quot;none&quot;)+labs(title=&quot;Isle of Wight NHS Trust&quot;)
    #g=g+scale_y_discrete(breaks=0:10)
    print(g)
  })
  
  #It would probable make sense to reshape the data presented in this table
  #For example, define columns based on facetB values, so we have one row per date range
  #I also need to sort the table by date
  output$view = reactiveTable(function() {
    head(subset(d,tableName==input$tbl,select=c('Name','fromDateStr','toDateStr','tableName','facetB','value')),n=100)
  })
  
})</pre>
<p>I get the feeling that it shouldn&#8217;t be too hard to create quite complex Shiny apps relatively quickly, pulling on things like Scraperwiki as a remote data source. One thing I haven&#8217;t tried is to use googleVis components, which would support in the first instance at least a sortable table view&#8230; Hmmm&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ouseful.wordpress.com/9127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ouseful.wordpress.com/9127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=9127&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ouseful.info/2012/11/28/quick-shiny-demo-exploring-nhs-winter-sit-rep-data/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/abbd9f90565ce9ae4d065d93a81d8c03?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tony Hirst</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/11/wight-sit-reps.png" medium="image">
			<media:title type="html">wight sit reps</media:title>
		</media:content>
	</item>
	</channel>
</rss>
