Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import time
|
|
7 |
import threading
|
8 |
import queue
|
9 |
|
|
|
|
|
10 |
# Your classes and functions...
|
11 |
|
12 |
class Organelle:
|
@@ -252,21 +254,15 @@ update_interval = st.slider("Update interval (seconds)", 0.1, 5.0, 1.0)
|
|
252 |
# Create a placeholder for the chart
|
253 |
chart_placeholder = st.empty()
|
254 |
|
255 |
-
|
256 |
-
def run_simulation():
|
257 |
env = Environment(100, 100)
|
258 |
for _ in range(initial_cells):
|
259 |
cell = Cell(random.uniform(0, env.width), random.uniform(0, env.height))
|
260 |
env.add_cell(cell)
|
|
|
261 |
fig = setup_figure(env)
|
262 |
|
263 |
-
|
264 |
-
try:
|
265 |
-
q.get(timeout=0.1)
|
266 |
-
break
|
267 |
-
except queue.Empty:
|
268 |
-
pass
|
269 |
-
|
270 |
env.update()
|
271 |
|
272 |
with fig.batch_update():
|
@@ -277,42 +273,12 @@ def run_simulation():
|
|
277 |
fig.data[i].marker.size = data["size"]
|
278 |
|
279 |
for i, (cell_type, counts) in enumerate(population_history.items()):
|
280 |
-
fig.data[i+5].y = counts
|
281 |
if cell_type != "modified" and cell_type != "plant_like":
|
282 |
-
fig.data[i+10].y = counts
|
283 |
else:
|
284 |
fig.data[13].y = population_history["plant_like"]
|
285 |
fig.data[14].y = population_history["modified"]
|
286 |
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
# Create a function to start the simulation
|
291 |
-
def start_simulation():
|
292 |
-
thread = threading.Thread(target=run_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 |
-
|
307 |
-
while True:
|
308 |
-
try:
|
309 |
-
fig = q.get(timeout=0.1)
|
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
|
|
|
7 |
import threading
|
8 |
import queue
|
9 |
|
10 |
+
|
11 |
+
|
12 |
# Your classes and functions...
|
13 |
|
14 |
class Organelle:
|
|
|
254 |
# Create a placeholder for the chart
|
255 |
chart_placeholder = st.empty()
|
256 |
|
257 |
+
if st.button("Start Simulation"):
|
|
|
258 |
env = Environment(100, 100)
|
259 |
for _ in range(initial_cells):
|
260 |
cell = Cell(random.uniform(0, env.width), random.uniform(0, env.height))
|
261 |
env.add_cell(cell)
|
262 |
+
|
263 |
fig = setup_figure(env)
|
264 |
|
265 |
+
for _ in range(100): # Run for 100 steps
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
env.update()
|
267 |
|
268 |
with fig.batch_update():
|
|
|
273 |
fig.data[i].marker.size = data["size"]
|
274 |
|
275 |
for i, (cell_type, counts) in enumerate(population_history.items()):
|
276 |
+
fig.data[i+5].y = counts
|
277 |
if cell_type != "modified" and cell_type != "plant_like":
|
278 |
+
fig.data[i+10].y = counts
|
279 |
else:
|
280 |
fig.data[13].y = population_history["plant_like"]
|
281 |
fig.data[14].y = population_history["modified"]
|
282 |
|
283 |
+
chart_placeholder.plotly_chart(fig, use_container_width=True)
|
284 |
+
time.sleep(update_interval)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|