This example file shows how to include interactive graphics into an RPub. It ain't pretty, but it is easy. It uses Jeroen Ooms' opencpu project to run the R code.

The file must have three parts.

The header files

Inlude the following in the header

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.0/css/bootstrap-combined.min.css">
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="https://raw.github.com/jverzani/wmd/master/showdown.js"></script>
<script src="https://raw.github.com/jverzani/wmd/master/manipulate.js"></script>

Locate the form controls and the graphic

Place the following where you want to see the form and graphic:

<div class="row">
  <div class="span4 well"><div id="insert"></div></div>
  <div class="span7"><div id="graph"></div></div>
</div>

The values insert and graph are IDs and must be unique to the page. We will reference them later.

Define the controls with showdown markup

The showdown markup makes it easy to define radio buttons, comboboxes and text entry areas. The following illustrates. As well, the expression to plot uses braces to indicate where the variables get substituted. THe example below uses this. Unfortunately, this all happens in JavaScript, not a R block or within the text.

<script>
$(document).ready(function() {
// define our manipulate objects. 
var inputs = [                     \\ trick for multiline entry
"xlab = ___[a label for x axis]",  \\ a text entry
"   n = (x) 10 () 100 () 1000",    \\ a radio button
"dist = {rnorm, rexp, (runif)}"    \\ a combobox (picker)
].join("\n")                       \\ JavaScript stuff
// define a plot expression
var expression = "hist( %dist%( %n% ), xlab=' %xlab% ')";
// create expression
manipulate("insert", "graph", inputs, expression)
})
</script>

Run this file through knitr's (or RStudio's) knitToHTML to
create a web page. It may not render in RStudio's preview widget, but
should work fine within a regular browser.

Demo

Here we show a form and a graph defined through javascript

More than one per page is possible, just use unique div IDs.