After working a while, I found a solution that seems to work and achieve the behavior that I want. Please note that I use twitter bootstrap css and javascript packages.
Basically, I make a group of buttons:
<div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary"> <input type="radio" name="options" id="home"> Option 1 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="option2"> Option 2 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="option3"> Option 3 </label>
Then in javascript from the mpld3 bulb example, I use:
$('.btn-primary').on('click', function(){ var qu = {"plot_type":$(this).find('input').attr('id')} $(this).addClass('active').siblings().removeClass('active'); $.ajax({ type: "POST", async:true, contentType: "application/json; charset=utf-8", url: "/query", data: JSON.stringify(qu), success: function (data) { var graph = $("#container"); graph.html(data); $("#container").show(); }, dataType: "html" }); });
Now I have a panel with radio buttons, with the active scene mode button set to βactiveβ, which requires only one click on one of the buttons to draw a new storyline.
EDIT: After learning more about the jar and Jinja2, it is also easy to pass the mpld3-generated html to the template, but there is a small getcha; it looks something like this.
In returning your python routing function:
return render_template('index.html', plot=mpld3_html)
Then in the html template you can reference this html with
{{plot|safe}}
Hope this helps someone else.