Skip to content

Commit

Permalink
Only set model_parameters once
Browse files Browse the repository at this point in the history
  • Loading branch information
Corvince committed Nov 13, 2024
1 parent e8b64cc commit 747d1c9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mesa/visualization/solara_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,17 @@ def ModelCreator(
)
user_params, fixed_params = split_model_params(user_params)

# set model_parameters to the default values for all parameters
model_parameters.value = {
**fixed_params,
**{k: v.get("value") for k, v in user_params.items()},
}
# Use solara.use_effect to run the initialization code only once
solara.use_effect(
# set model_parameters to the default values for all parameters
lambda: model_parameters.set(
{
**fixed_params,
**{k: v.get("value") for k, v in user_params.items()},
}
),
[],
)

def on_change(name, value):
model_parameters.value = {**model_parameters.value, name: value}
Expand Down

0 comments on commit 747d1c9

Please sign in to comment.