#!/usr/bin/env python # coding: utf-8 # In[ ]: import ipycytoscape # In[ ]: import json with open("geneData.json") as fi: json_file = json.load(fi) with open("geneStyle.json") as fi: s = json.load(fi) # In[ ]: cytoscapeobj = ipycytoscape.CytoscapeWidget() cytoscapeobj.graph.add_graph_from_json(json_file) cytoscapeobj.set_style(s) # ## Setting the tooltip text # # 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'` # In[ ]: cytoscapeobj.set_tooltip_source('name') # In[ ]: cytoscapeobj.set_layout(name = 'cola', nodeSpacing = 5, edgeLengthVal = 45, animate = True, randomize = False, maxSimulationTime = 1500) # In[ ]: cytoscapeobj # In[ ]: # edits graph directly cytoscapeobj.set_layout(nodeSpacing=100) cytoscapeobj.get_layout() # In[ ]: # connects a slider to the nodeSpacing of the graph import ipywidgets as widgets node_range = widgets.IntSlider() 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)