I’m unable to get network graph for a call back in my web app which changes according to slider
Here’s the code
def update_graph(year_value):
path="C:/Users/ilike/Desktop/aseann.xlsx"
wb=xl.load_workbook(path)
countries=wb.sheetnames
YRA=format(year_value)
G=nx.Graph()
pos=nx.spring_layout(G,dim=3)
for c in countries:
ws=wb[c]
max_r=ws.max_row
max_c=ws.max_column
for r in range(4,max_r,3):
yr_ob=ws.cell(row=r,column=1)
yr=yr_ob.value
if yr==YRA:
for cl in range(2,max_c):
cob=ws.cell(row=3,column=cl)
cnt=cob.value
cov=ws.cell(row=r,column=cl)
ov=cov.value
if ov!=0 and ov!=None:
G.add_edge(c,cnt)
else:
continue
nx.draw(G,with_labels=1)
pos=nx.spring_layout(G,dim=3)
edge_trace=go.Scatter3d(x=[],y=[],z=[],line={'width':0.5,'color':'#888'},hoverinfo='none',mode='lines')
for edge in G.edges():
x0,y0,z0=pos.get(edge[0])
x1,y1,z1=pos.get(edge[1])
edge_trace['x']+=tuple([x0,x1,None])
edge_trace['y']+=tuple([y0,y1,None])
edge_trace['z']+=tuple([z0,z1,None])
node_trace = go.Scatter3d(x=[], y=[], text=[], mode='markers', hoverinfo='text')
for node in G.nodes():
x,y,z=pos.get(node)
node_trace['x']+=tuple([x])
node_trace['y']+=tuple([y])
node_trace['z']+=tuple([z])
return{"data":[edge_trace, node_trace],
"layout": go.Layout(title='Network Graph With Dash', showlegend=False, hovermode='closest',
margin={'b': 20, 'l': 5, 'r': 5, 't': 40},
xaxis={'showgrid': False, 'zeroline': False, 'showticklabels': False},
yaxis={'showgrid': False, 'zeroline': False, 'showticklabels': False})}
if name == ‘main’:
app.run_server(debug=True)