Pjpy
Pjpy
while priority_queue:
current_distance, current_node = heapq.heappop(priority_queue)
# Nodes can only be added once to the queue with their shortest distance
if current_distance > distances[current_node]:
continue
@app.callback(
Output('graph-output', 'figure'),
Output('output', 'children'),
Input('run-button', 'n_clicks'),
State('edges-input', 'value'),
State('start-node', 'value'),
)
def update_output(n_clicks, edges_input, start_node):
if n_clicks is None:
return go.Figure(), ""
edge_trace = go.Scatter(
x=edge_x, y=edge_y,
line=dict(width=0.5, color='#888'),
hoverinfo='none',
mode='lines'
)
node_x = []
node_y = []
node_text = []
node_trace = go.Scatter(
x=node_x, y=node_y,
mode='markers+text',
text=node_text,
hoverinfo='text',
marker=dict(
showscale=True,
colorscale='YlGnBu',
size=10,
color=list(distances.values()), # Color by distance
colorbar=dict(title='Distance')
)
)
path_edge_x = []
path_edge_y = []
@app.callback(
Output('num-nodes', 'value'),
Output('edges-input', 'value'),
Output('start-node', 'value'),
Input('reset-button', 'n_clicks'),
)
def reset(n_clicks):
if n_clicks is None:
raise dash.exceptions.PreventUpdate
return 5, "", ""
if __name__ == '__main__':
app.run_server(debug=True)