Sephfox commited on
Commit
bb172ed
·
verified ·
1 Parent(s): 3a97d6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -213,7 +213,9 @@ def setup_figure(env):
213
 
214
  # Total population over time
215
  for cell_type, counts in env.population_history.items():
216
- fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type), row=1, col=2)# Individual population charts
 
 
217
  for i, cell_type in enumerate(cell_types):
218
  if cell_type == "modified":
219
  fig.add_trace(go.Scatter(y=env.population_history[cell_type], mode='lines',
@@ -282,7 +284,8 @@ def run_simulation():
282
  fig.data[13].y = population_history["plant_like"]
283
  fig.data[14].y = population_history["modified"]
284
 
285
- q.put(fig)
 
286
 
287
  # Create a function to start the simulation
288
  def start_simulation():
@@ -290,9 +293,14 @@ def start_simulation():
290
  thread.start()
291
 
292
  # Create a function to stop the simulation
 
 
293
  def stop_simulation():
 
 
294
  q.put(None)
295
 
 
296
  start_button = st.button("Start Simulation", on_click=start_simulation)
297
  stop_button = st.button("Stop Simulation", on_click=stop_simulation)
298
 
@@ -302,8 +310,9 @@ while True:
302
  if fig is not None:
303
  chart_placeholder.plotly_chart(fig, use_container_width=True)
304
  else:
305
- print("Received None figure from queue. Stopping simulation.")
306
  break
307
  except queue.Empty:
308
  time.sleep(0.1)
 
 
309
  continue
 
213
 
214
  # Total population over time
215
  for cell_type, counts in env.population_history.items():
216
+ fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type), row=1, col=2)
217
+
218
+ # Individual population charts
219
  for i, cell_type in enumerate(cell_types):
220
  if cell_type == "modified":
221
  fig.add_trace(go.Scatter(y=env.population_history[cell_type], mode='lines',
 
284
  fig.data[13].y = population_history["plant_like"]
285
  fig.data[14].y = population_history["modified"]
286
 
287
+ if q.empty():
288
+ q.put(fig)
289
 
290
  # Create a function to start the simulation
291
  def start_simulation():
 
293
  thread.start()
294
 
295
  # Create a function to stop the simulation
296
+ stop_button_pressed = False
297
+
298
  def stop_simulation():
299
+ global stop_button_pressed
300
+ stop_button_pressed = True
301
  q.put(None)
302
 
303
+ # Create buttons to start and stop the simulation
304
  start_button = st.button("Start Simulation", on_click=start_simulation)
305
  stop_button = st.button("Stop Simulation", on_click=stop_simulation)
306
 
 
310
  if fig is not None:
311
  chart_placeholder.plotly_chart(fig, use_container_width=True)
312
  else:
 
313
  break
314
  except queue.Empty:
315
  time.sleep(0.1)
316
+ if stop_button_pressed:
317
+ break
318
  continue