title: IPython Notebook: programmatically trigger a cell from JavaScript
body: <p>So, I've been playing around with the IPython notebook for a couple of days, and I love it!  But, now I need to do something slightly fancy:</p>
  
  <p>I have a markdown cell; in it, there is an HTML input and button, and some JavaScript attached to the button that will take the contents of the input, and inject it into the python kernel.  Here's the cell:</p>
  
  <pre><code>&lt;h3&gt;Use JS to pass DOM info to Python kernel: &lt;/h3&gt;
  &lt;input id='testinput' value='FragmentId'&gt;&lt;/input&gt;
  &lt;button id='testComms' onclick='JS2PY()'&gt;:D&lt;/button&gt;
  
  &lt;script type="text/javascript"&gt;    
      function JS2PY(){
          var input = document.getElementById('testinput').value,
              kernel = IPython.notebook.kernel;
  
          kernel.execute('testVar = "' + input + '"');
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Works like a charm!  Next up I have a python code cell; it does some ROOT stuff, and makes a plot based on whatever value got injected into the python kernel from the above cell.  Here's the python cell:</p>
  
  <pre><code>def testfunc():
      from ROOT import TH1, TFile, TTree
      import rootnotes, numpy
  
      c2 = rootnotes.canvas("treeData", (600,400))
  
      testfile = TFile("fragment27422_000.root")
      testtree = testfile.Get("FragmentTree")
  
      buff = numpy.zeros(1, dtype=float)
  
      testtree.Branch(testVar, buff)
  
      testtree.Draw(testVar)
      return c2
  
  testfunc()
  </code></pre>
  
  <p>Also works no problem if I manually go and run the cell - great!  But what I really want, is this python cell to run automatically when I click that button in the markdown cell above, after promoting the <code>testVar</code> variable.  Apologies and thanks in advance - this is only day two of python for me, so it's probably something really simple.</p>