streamlit 1.38.0
streamlit-agraph 0.0.45
I am modeling a process using simpy and would like to use a streamlit agraph to visualize the process changing during the simulation. However, I am getting “streamlit.errors.DuplicateWidgetID: There are multiple identical st.streamlit_agraph.agraph` widgets with the same generated key.”
The goal is to update the same vice replicating additional graphs, does anyone have a suggestion as to what I need to do differently?
Example code:
import streamlit as st
from streamlit_agraph import agraph, Node, Edge, Config
import simpy
import random
def update_graph(env, graph_placeholder, nodes, edges, config):
while True:
yield env.timeout(100)
with graph_placeholder:
i = random.randint(1, 5)
# Update graph - let's change the color of a node dynamically
nodes[0].color = f"#{''.join([format(255 - i * 40, '02x') for i in [255 - i * 20, 0, 0]])}"
agraph(nodes=nodes, edges=edges, config=config)
nodes = [
Node(id="A", label="Node A", color="#ff0000"),
Node(id="B", label="Node B", color="#00ff00"),
Node(id="C", label="Node C", color="#0000ff"),
]
edges = [
Edge(source="A", target="B", label="A->B"),
Edge(source="B", target="C", label="B->C"),
Edge(source="C", target="A", label="C->A"),
]
config = Config(width=500, height=500, directed=True)
graph_placeholder = st.empty()
with graph_placeholder:
agraph(nodes, edges, config)
if st.button('Run Simulation'):
env = simpy.Environment()
env.process(update_graph(env, graph_placeholder, nodes, edges, config))
env.run(until=1000)