Skip to content

Commit 10f2d57

Browse files
committed
Define reactive dependencies in 1 place
1 parent c6b0530 commit 10f2d57

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

mesa/experimental/jupyter_viz.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# TODO: Turn this function into a Solara component once the current_step.value
1818
# dependency is passed to measure()
1919
def Card(
20-
model, measures, agent_portrayal, space_drawer, current_step, color, layout_type
20+
model, measures, agent_portrayal, space_drawer, dependencies, color, layout_type
2121
):
2222
with rv.Card(
2323
style_=f"background-color: {color}; width: 100%; height: 100%"
@@ -27,11 +27,11 @@ def Card(
2727
if space_drawer == "default":
2828
# draw with the default implementation
2929
components_matplotlib.SpaceMatplotlib(
30-
model, agent_portrayal, dependencies=[current_step.value]
30+
model, agent_portrayal, dependencies=dependencies
3131
)
3232
elif space_drawer == "altair":
3333
components_altair.SpaceAltair(
34-
model, agent_portrayal, dependencies=[current_step.value]
34+
model, agent_portrayal, dependencies=dependencies
3535
)
3636
elif space_drawer:
3737
# if specified, draw agent space with an alternate renderer
@@ -44,7 +44,7 @@ def Card(
4444
measure(model)
4545
else:
4646
components_matplotlib.PlotMatplotlib(
47-
model, measure, dependencies=[current_step.value]
47+
model, measure, dependencies=dependencies
4848
)
4949
return main
5050

@@ -115,6 +115,8 @@ def do_reseed():
115115
reactive_seed.value = model.random.random()
116116

117117
# jupyter
118+
dependencies = [current_step.value, reactive_seed.value]
119+
118120
def render_in_jupyter():
119121
with solara.GridFixed(columns=2):
120122
UserInputs(user_params, on_change=handle_change_model_params)
@@ -126,11 +128,11 @@ def render_in_jupyter():
126128
if space_drawer == "default":
127129
# draw with the default implementation
128130
components_matplotlib.SpaceMatplotlib(
129-
model, agent_portrayal, dependencies=[current_step.value]
131+
model, agent_portrayal, dependencies=dependencies
130132
)
131133
elif space_drawer == "altair":
132134
components_altair.SpaceAltair(
133-
model, agent_portrayal, dependencies=[current_step.value]
135+
model, agent_portrayal, dependencies=dependencies
134136
)
135137
elif space_drawer:
136138
# if specified, draw agent space with an alternate renderer
@@ -144,7 +146,7 @@ def render_in_jupyter():
144146
measure(model)
145147
else:
146148
components_matplotlib.PlotMatplotlib(
147-
model, measure, dependencies=[current_step.value]
149+
model, measure, dependencies=dependencies
148150
)
149151

150152
def render_in_browser():
@@ -178,7 +180,7 @@ def render_in_browser():
178180
measures,
179181
agent_portrayal,
180182
space_drawer,
181-
current_step,
183+
dependencies,
182184
color="white",
183185
layout_type=layout_types[i],
184186
)

0 commit comments

Comments
 (0)