var graph = [
[0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
[1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0],
[1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0],
[1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1],
[0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1],
[0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1],
[0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1],
[1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1],
[1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0],
[1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0]
];
//Setting CORS to call the igraph package
ocpu.seturl("https://public.opencpu.org/ocpu/library/igraph/R");
var graphSession;
$('#output').text(graph.toString());
$('#adjMatrix').click(function() {
ocpu.call("graph_from_adjacency_matrix", {
adjmatrix: graph,
mode: 'directed',
weighted: true
}, function(session) {
graphSession = session;
//Retrieve session console asynchronously
graphSession.getConsole(function(outtxt) {
$("#output").text(outtxt);
$("#centralize").prop('disabled', false);
});
}).fail(function() {
alert("Error: " + req.responseText);
});
});
$('#centralize').click(function() {
var centralizeReq = ocpu.call("centralization.closeness", {
graph: graphSession,
mode: "all",
normalized: true
}, function(centralizeSession) {
centralizeSession.getConsole(function(outtxt) {
$("#output").text(outtxt);
});
}).fail(function() {
alert("Error: " + req.responseText);
});
});
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdn.opencpu.org/opencpu-0.4.js"></script>
<div>
<textarea name="" id="output" cols="60" rows="10"></textarea>
<br />
<button id="adjMatrix">Graph From Adj</button>
<button id="centralize" disabled>Centralize</button>
</div>