import ipycytoscape
import json
with open("geneData.json") as fi:
json_file = json.load(fi)
with open("geneStyle.json") as fi:
s = json.load(fi)
cytoscapeobj = ipycytoscape.CytoscapeWidget()
cytoscapeobj.graph.add_graph_from_json(json_file)
cytoscapeobj.set_style(s)
You can control what shows up in the tooltip when you click on a node with the tooltip_source
attribute. By default the widget will look for data['tooltip']
and if that exists use it as the text for the tooltip. Using the set_tooltip_source
function you can choose to use other attributes, here we use 'name'
cytoscapeobj.set_tooltip_source('name')
cytoscapeobj.set_layout(name = 'cola',
nodeSpacing = 5,
edgeLengthVal = 45,
animate = True,
randomize = False,
maxSimulationTime = 1500)
cytoscapeobj
CytoscapeWidget(cytoscape_layout={'name': 'cola', 'nodeSpacing': 5, 'edgeLengthVal': 45, 'animate': True, 'ran…
# edits graph directly
cytoscapeobj.set_layout(nodeSpacing=100)
cytoscapeobj.get_layout()
{'name': 'cola', 'nodeSpacing': 100, 'edgeLengthVal': 45, 'animate': True, 'randomize': False, 'maxSimulationTime': 1500}
# connects a slider to the nodeSpacing of the graph
import ipywidgets as widgets
node_range = widgets.IntSlider(value=100)
output = widgets.Output()
display(node_range, output)
def on_value_change(change):
with output:
cytoscapeobj.set_layout(nodeSpacing = node_range.value)
cytoscapeobj.get_layout()
node_range.observe(on_value_change)
IntSlider(value=100)
Output()