import ipycytoscape
import ipywidgets as widgets
import json
with open("colaData.json") as fi:
json_file = json.load(fi)
cytoscapeobj = ipycytoscape.CytoscapeWidget()
cytoscapeobj.graph.add_graph_from_json(json_file)
cytoscapeobj
CytoscapeWidget(cytoscape_layout={'name': 'cola'}, cytoscape_style=[{'selector': 'node', 'css': {'background-c…
#The reason why the graph goes gray here it's because we're overwriting the style and not giving it any colors
#this will be done later on when we attribute the `highlighted` class to the edges and nodes on the `for`
cytoscapeobj.set_style([{
"selector": "edge.highlighted",
"css": {
"line-color": "red"
}
},
{
"selector": "node.highlighted",
"css": {
"background-color": "blue"
},
}])
btn = widgets.Button(description="red edges", disabled=False)
def btn_callback(b):
for edge in cytoscapeobj.graph.edges:
classes = set(edge.classes.split(" "))
classes.add("highlighted")
edge.classes = " ".join(classes)
btn.on_click(callback=btn_callback)
display(btn)
Button(description='red edges', style=ButtonStyle())
cytoscapeobj
CytoscapeWidget(cytoscape_layout={'name': 'cola'}, cytoscape_style=[{'selector': 'edge.highlighted', 'css': {'…
btn = widgets.Button(description="blue nodes", disabled=False)
def btn_callback(b):
for node in cytoscapeobj.graph.nodes:
classes = set(node.classes.split(" "))
classes.add("highlighted")
node.classes = " ".join(classes)
btn.on_click(callback=btn_callback)
display(btn)
Button(description='blue nodes', style=ButtonStyle())