<script>
  <stage width="1500" height="1000">
    <location id="term" program="gnome-terminal"
              x="50" y="50" width="600" height="500"/>
    <location id="ff" program="firefox"
              x="700" y="50" width="700" height="900"/>
  </stage>
  <scene id="setup">
    <shot location="term">
      <action>
R
      </action>
      <dialogue>
The first step is to start R        
      </dialogue>
    </shot>
    <shot duration="1"/>
    <shot location="term">
      <action linedelay="1000"><![CDATA[
library(DOM)
page <- htmlPage()
      ]]></action>
      <dialogue>
Within R, we load the 'DOM' package.
Then we use the htmlPage() function to
create a web socket connection between R and the browser.
      </dialogue>
    </shot>
  </scene>
  <scene id="plot">
    <shot location="term">
      <action>
library(lattice)
xyplot(mpg ~ disp, mtcars, pch=16, col=rgb(0,0,1,.5), cex=2)
      </action>
      <dialogue>
We use the 'lattice' package to produce a plot.      
      </dialogue>
    </shot>
  </scene>
  <scene id="rearrange">
    <shot duration="2">
      <action echo="FALSE"><![CDATA[
library(wmctrl)
# Wait for R graphics window
Sys.sleep(1)
RGID <- getWindowID("R Graphics")
locateWindow(RGID, 400, 10)
      ]]></action>
    </shot>
  </scene>
  <scene id="append">
    <shot location="term">
      <action linedelay="1000"><![CDATA[
library(gridSVG)
svg <- grid.export(NULL)$svg
      ]]></action>
      <dialogue>
We use the 'gridSVG' package to convert the plot to SVG.
      </dialogue>
    </shot>
    <shot location="term">
      <action></action>
    </shot>
    <shot location="term">
      <action keydelay="50"><![CDATA[
dev.off()
library(XML)
appendChild(page, svgNode(saveXML(svg)), ns=TRUE, 
            response=nodePtr())      
      ]]></action>
      <dialogue>
Then we use the appendChild() function from the 'DOM' package to
send the plot to the browser.
      </dialogue>
    </shot>
    <shot location="term">
      <action>
q("no")
      </action>
    </shot>
  </scene>
</script>
