Search code examples
htmlneo4jneo4jrestclient

HTML Generation using neo4jrestclient


So I was using the neo4jrestclient, and I noticed that in the class of QuerySequece, there's a .to_html()function (https://github.com/versae/neo4j-rest-client/blob/master/neo4jrestclient/query.py) However, when I try using it I get the 'Unable to display the graph or the table' error.

I haven't found a working example of it. I was wondering if anyone has gotten this working.

Much thanks appreciated.


Solution

  • The function .to_html() is a function that IPython uses in order to render rich content inside Notebooks. When running inside a Notebook, neo4jrestclient asks for extra information to the Neo4j server, so it can draw the actual graph returned. Therefore, if you try to run a query inside an IPython Notebook, a D3 graph should be rendered automatically.

    from neo4jrestclient.client import GraphDatabase, Node, Relationship
    gdb = GraphDatabase(url="http://localhost:7474")
    gdb.query("MATCH (me)-[r]-() RETURN me, r LIMIT 10")
    

    A running example can be seen in this gist. Although it's still a work in progress. I think that I could add an option to populate the needed fields in case you wanted to use the .to_html() outside the IPython Notebook. All you need to do is to make neo4jrestclient believe that it's running inside of one by modifying the function neo4jrestclient.utils.in_ipnb() making it to always return True. Let me know if you would use that feature and I will add it.

    On the other hand, I am developing ipython-cypher, to have a better integration of IPython, Pandas, NetworkX, and matplotlib with Neo4j, but it's still in alpha.

    Update: Now you can add data_contents=True to return the extra data.

    results = gdb.query(query, data_contents=True)
    

    Data will be in results.rows and results.graph.