Sephfox commited on
Commit
d015dfd
1 Parent(s): fc14acd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -2
app.py CHANGED
@@ -240,8 +240,55 @@ def format_number(num):
240
  else:
241
  return str(num)
242
 
243
- # Streamlit app
244
- st.title("Continuous Cell Evolution Simulation")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
 
246
  # Sidebar for controls and live statistics
247
  st.sidebar.header("Simulation Controls")
 
240
  else:
241
  return str(num)
242
 
243
+ def update_chart():
244
+ global fig # Assuming fig is a global variable
245
+
246
+ # Clear existing traces
247
+ fig.data = []
248
+
249
+ # Cell positions
250
+ cell_types = [cell.cell_type for cell in st.session_state.env.cells]
251
+ x_positions = [cell.x for cell in st.session_state.env.cells]
252
+ y_positions = [cell.y for cell in st.session_state.env.cells]
253
+
254
+ fig.add_trace(go.Scatter(x=x_positions, y=y_positions, mode='markers',
255
+ marker=dict(color=[colors[ct] for ct in cell_types]),
256
+ text=cell_types, hoverinfo='text'), row=1, col=1)
257
+
258
+ # Population history
259
+ for cell_type, counts in st.session_state.env.population_history.items():
260
+ fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type,
261
+ line=dict(color=colors[cell_type])), row=1, col=2)
262
+
263
+ # Population by cell type
264
+ for cell_type, counts in st.session_state.env.population_history.items():
265
+ fig.add_trace(go.Scatter(y=counts, mode='lines', name=cell_type,
266
+ line=dict(color=colors[cell_type])), row=2, col=1)
267
+
268
+ # Organelle distribution
269
+ organelle_counts = {"nucleus": 0, "mitochondria": 0, "chloroplast": 0,
270
+ "endoplasmic_reticulum": 0, "golgi_apparatus": 0}
271
+ for cell in st.session_state.env.cells:
272
+ for organelle in cell.organelles:
273
+ organelle_counts[organelle] += 1
274
+
275
+ fig.add_trace(go.Bar(x=list(organelle_counts.keys()), y=list(organelle_counts.values()),
276
+ name="Organelles"), row=2, col=2)
277
+
278
+ # Update axis labels and layout
279
+ fig.update_xaxes(title_text="X", row=1, col=1)
280
+ fig.update_yaxes(title_text="Y", row=1, col=1)
281
+ fig.update_xaxes(title_text="Time", row=1, col=2)
282
+ fig.update_yaxes(title_text="Population", row=1, col=2)
283
+ fig.update_xaxes(title_text="Time", row=2, col=1)
284
+ fig.update_yaxes(title_text="Population", row=2, col=1)
285
+ fig.update_xaxes(title_text="Organelle", row=2, col=2)
286
+ fig.update_yaxes(title_text="Count", row=2, col=2)
287
+
288
+ fig.update_layout(height=800, width=1200, title_text="Advanced Cell Evolution Simulation")
289
+
290
+ # Update the chart placeholder
291
+ chart_placeholder.plotly_chart(fig)
292
 
293
  # Sidebar for controls and live statistics
294
  st.sidebar.header("Simulation Controls")