Dear fellow Web2py user,
I am trying to get a json variable into a D3 graph. This was successfull with a simple list of dictionaries within the python/JS vairable. But nof I want to get the famous flare data structure into my view.
In the controller I have:
def view_dendo():
import json
flare= [{ 'name': 'flare', 'children': [ { 'name': 'analytics', 'children': [ { 'name': 'cluster', 'children': [ {'name':'graph', 'size': 3938}, {'name': 'CommunityStructure', 'size': 3812}, ] }, { 'name': 'graph', 'children': [ {'name':'BetweennessCentrality', 'size': 3534}, {'name': 'LinkDistance', 'size': 5731}, {'name': 'MaxFlowMinCut', 'size': 7840}, {'name':'ShortestPaths', 'size': 5914}, {'name': 'SpanningTree', 'size': 3416} ] }, { 'name': 'CommunityStructure' } ] } ] }]
return dict(flare=XML(json.dumps(flare)))
In the View I have:
var flare = {{=flare}} ;
var nodes = cluster.nodes( flare ),
links = cluster.links(nodes);
The view doesn't matter yet because the Chrome console comes with the message:
Uncaught SyntaxError: Unexpected token }
Comming from web2py.js
When I place the requested variable between [] : var flare = [ {{=flare}} ] ;
The message is the same but does not ref to web2py.js
Checking the Chrome console the dictionary is in the view indeed with 2 } at the end ...ructure"}]}}] ;
I checked the python json.dumps documentation and changed the [] in () in the dictionary in the controller.
This resulted in the same error however not with a double }} at the end ....ze": 3416}]}]}} ;