WestHealth / pyvis

Python package for creating and visualizing interactive network graphs.
http://pyvis.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
975 stars 165 forks source link

usage of Network.set_options() #42

Closed ffollett closed 5 years ago

ffollett commented 5 years ago

I'm trying to provide the options string generated by the dynamic network configuration tool to my network object before calling show() on it again, but I get an error every time.

import networkx as nx
from pyvis.network import Network

G = nx.star_graph(20)
nodes = G.nodes.data()
edges = G.edges.data()

g = Network(notebook=True)

{g.add_node(node[0]) for node in nodes}
{g.add_edge(edge[0], edge[1]) for edge in edges}

g.set_options('var options = {  "nodes": {    "color": {      "hover": {        "border": "rgba(231,44,233,1)"      }    },    "shape": "dot"  },  "edges": {    "arrowStrikethrough": false,    "color": {      "highlight": "rgba(132,48,51,1)",      "hover": "rgba(128,25,132,1)",      "inherit": false    },    "smooth": {      "type": "vertical",      "forceDirection": "none"    }  },  "physics": {    "barnesHut": {      "gravitationalConstant": -80000,      "springLength": 250,      "springConstant": 0.001    },    "minVelocity": 0.75  }}')

g.show("ex.html")

This code returns the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-ae5445ab43fb> in <module>()
      4 {g.add_edge(edge[0], edge[1]) for edge in edges}
      5 g.show_buttons()
----> 6 g.set_options('var options = {  "nodes": {    "color": {      "hover": {        "border": "rgba(231,44,233,1)"      }    },    "shape": "dot"  },  "edges": {    "arrowStrikethrough": false,    "color": {      "highlight": "rgba(132,48,51,1)",      "hover": "rgba(128,25,132,1)",      "inherit": false    },    "smooth": {      "type": "vertical",      "forceDirection": "none"    }  },  "physics": {    "barnesHut": {      "gravitationalConstant": -80000,      "springLength": 250,      "springConstant": 0.001    },    "minVelocity": 0.75  }}')
      7 g.show("ex.html")

AttributeError: 'Network' object has no attribute 'set_options'

Am I using set_options() incorrectly? I tried to bypass it by calling g.options.set(), but that gave the same error. I see the function definitions in the code, so I don't understand why they're not being found. I also noticed that in the readthedocs.io page for network.py doesn't have an entry for set_options. Perhaps unrelated.

boludo00 commented 5 years ago

The latest code on github reflects this change, however I haven't gotten around to releasing the latest update including this change. You would have to fork the repo and do a local install! I'll try and get this latest version out asap.

boludo00 commented 5 years ago

You can now update to latest pyvis version 0.1.7.0 which should have this change. Also documentation is updated with a small use case!