I was also interested in this task, and this is what I came up with. First I created json, which will load into the visualization using Python ( json sample ). Json should have the following form:
{ "nodes": [ {"name":node_name, "group":node_group}, {"name":another_node_name, "group":another_node_group}, ... ], "links":[ {"source"link_source, "target":link_target, "value":link_value, {"source"another_link_source, "target":another_link_target, "value":another_link_value}, ... ] }
Then it is just a matter of pointing your application to your json files. I used the Python Flask library to create a simple server that could serve my json files:
Then I downloaded the server and my json into Amazon web services using this elastic bean glass tutorial to deploy the application and change the javascript code as follows:
<!DOCTYPE html> <html class="ocks-org do-not-copy"> <meta charset="utf-8"> <title>Dramatic Co-occurrence</title> <style> @import url(../style.css?aea6f0a); d3_plot { font-size: 80%; } body.svg { margin-left: 0px; } .background { fill: #eee; } line { stroke: #fff; } text.active { fill: red; } </style> <script type="text/javascript" src="http://d3js.org/d3.v2.min.js?2.8.1"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script> <header> </header> <h1>Character Co-occurrence in Shakespearean Drama</h1> <aside style="margin-top:20px;"> <p>Play: <select id="selected_json"> <option value='"http://tdm-api-dev.elasticbeanstalk.com/api/json/king_henry_the_fifth.json"'>Henry VIII</option> <option value='"http://tdm-api-dev.elasticbeanstalk.com/api/json/romeo_and_juliet.json"'>Romeo and Juliet</option> <option value='"http://tdm-api-dev.elasticbeanstalk.com/api/json/hamlet.json"'>Hamlet</option> </select> <i> </i> Order: <select id="order"> <option value="name">by Name</option> <option value="count">by Frequency</option> <option value="group">by Cluster</option> </select> <p>This application visualizes the degree to which characters in Shakespeare plays appear together. <p>Each colored cell represents two characters that appeared in the same scene, and darker cells indicate characters that co-occurred more frequently. <p>Use the drop-down menus to select a different play, reorder the matrix, and explore the data. <p>Built with data from ProQuest Chadwyck Healey <a href="http://www.proquest.com/products-services/literature_online.html">Literature Online Collections</a>. </aside> <d3_plot></d3_plot> <script> function select_json(new_json) { var margin = { top: 120, right: 0, bottom: 10, left: 160 }, width = 800, height = 800; var x = d3.scale.ordinal().rangeBands([0, width]), z = d3.scale.linear().domain([0, 4]).clamp(true), c = d3.scale.category10().domain(d3.range(10)); var svg = d3.select("d3_plot").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .style("margin-left", "0px") .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); </script> [1]: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html
This created a web page that looks like the image below, which you can see in action here . Hope this helps others!
PS When creating the page, it was very useful for me to open my html in Chrome, and then use more tools --> developer tools to help me debug javascript errors.
