I am trying to modify this function in order to correctly display the interactive buttons. I am using pyvis
to visualize a graph created on Networkx
. Despite including N.show_buttons(filter_=True)
, the buttons do not appear in the corresponding html file. Also, how can I add a title to the html page that is produced?
def visualize(identity_id,html_name):
#create subgraph using the provided identity_id
classx = [n for n in G.nodes() if G.nodes[n]['modularity'] ==
G.nodes[identity_id]['modularity']]
SG = G.subgraph(classx)
#instantiate the Network object
N = Network(height='100%', width='100%', bgcolor='#ffffff',
font_color='black',notebook = True, directed=False)
#this line effects the physics of the html File
N.barnes_hut(spring_strength=0.006)
#Change colors of nodes and edges
for n in SG:
if (SG.nodes[n]['category']=='cust') and (SG.nodes[n]['status']=='ACTIVE'): # assign color to nodes based on cust status
color = 'green'
shape = 'square'
if (SG.nodes[n]['category']=='cust') and (SG.nodes[n]['status']=='CLOSED'): # assign color to nodes based on cust status
color = 'red'
shape = 'square'
elif SG.nodes[n]['category']=='app':# assign shape to nodes based on cust versus app
color = 'blue'
shape = 'triangle'
N.add_node(n, label=n, color=color,shape = shape)
for e in SG.edges:
if e in SG.edges: # add the edges to the graph
color = 'black'
width = 2
N.add_edge(e[0],e[1],color=color, width=width)
N.show_buttons(filter_=True)
#generate html file
N.show(f'subgraph_{html_name}.html')