Assuming I have a ipycytoscape graph as follows:
railnet= '''{
"nodes": [
{"data": { "id": "BER", "label":"HBf BER", "classes":"east"}},
{"data": { "id": "MUN", "label":"HBf MUN", "classes":"west"}},
{"data": { "id": "FRA", "label":"HBf FRA", "classes":"west"}}
],
"edges": [
{"data": { "id": "line1", "source": "BER", "target": "MUN","label":"200km/h"}},
{"data": { "id": "line2", "source": "MUN", "target": "FRA","label":"200km/h"}},
{"data": { "id": "line3", "source": "FRA", "target": "BER","label":"250km/h" }}
]
}'''
railnetJSON = json.loads(railnet)
ipycytoscape_obj3 = ipycytoscape.CytoscapeWidget()
ipycytoscape_obj3.graph.add_graph_from_json(railnetJSON, directed=False) # I am telling I dont want directions
ipycytoscape_obj3
How can I access easily a node with the id?
this does not work:
ipycytoscape_obj3.graph.nodes['BER']. # --> wrong
This is because the id
information is inside of data.
I didn't test it but maybe nodes['data']['BER']
would work?
You can check this example for a bit more complex edge/node interaction. Check the Pandas session on this notebook. And as always, feel free to open an issue on the repo.
Thanks!