I’m posting this mostly to show how to:
- use the Google spreadsheet data-munging “hack” from the previous post in a Shiny context
- include it seamlessly into a web page, and
- run it locally without a great deal of wrangling
The code for the app is in this gist. It is unsurprisingly just like some spiffy other code you’ve seen apart from my aesthetic choices (Sochi blue! lines+dots! and, current rankings next to country names).
I won’t regurgitate the code here since it’s just as easy to view on github. You’re seeing the live results of the app below (unless you’ve been more conservative than most folks with your browser security settings),
but the app is actually hosted over at Data Driven Security, a blog and (woefully underpowered so reload if it coughs up blood, pls) Shiny server that I run with @jayjacobs. It appears in this WordPress post with the help of an
IFRAME. It’s essentially the same technique the RStudio/Shiny folks use in many of their own examples.
The app uses
bootstrapPage() to help make a more responsive layout which will react nicely in an
IFRAME setting (since you won’t know the width of the browser area you’re trying to fit the Shiny output into).
ui.R file, I have the
plotOutput() configured to scale to 100% of container width:
and then create a seamless
IFRAME that also sizes to max-width:
<iframe src="http://shiny.dds.ec/sochi2014/" style="max-width:100%" width="100%" height="500px" scrolling="no" frameborder="no" seamless="seamless"> </iframe>
The really cool part (IMO) about many Shiny apps is that you don’t need to rely on the external server to work with the visualization/output. Provided that:
- the authors have coded their app to support local execution…
- and presented the necessary
global.R, HTML/CSS & data files either as a github gist or a zip/gz/tar.gz file…
- and you have the necessary libraries installed
then, you can start the app with a simple
Rscript -e "shiny::runGist(8949172, launch.browser=TRUE)"
Rscript -e "shiny::runUrl('http://dds.ec/apps/sochi2014.tar.gz', launch.browser=TRUE)"
There is some danger doing this if you haven’t read through the R code prior, since it’s possible to stick some fairly malicious operations in an R script (hey, I’m an infosec professional, so we’re always paranoid :-). But, if you stick with using a gist and do examine the code, you should be fine.