Repository: projectmesa/mesa
Pull request #1798 (2023-09-12 20:36:59)

Add support for solara.Checkbox user input

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/projectmesa/mesa/pull/1798?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=projectmesa) Report
Patch coverage: **`100.00%`** and project coverage change: **`+0.04%`** :tada:
> Comparison is base [(`ccde77b`)](https://app.codecov.io/gh/projectmesa/mesa/commit/ccde77bd31b27a7d72152eb9cc41fbee16364d38?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=projectmesa) 81.79% compared to head [(`8326995`)](https://app.codecov.io/gh/projectmesa/mesa/pull/1798?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=projectmesa) 81.83%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #1798      +/-   ##
==========================================
+ Coverage   81.79%   81.83%   +0.04%     
==========================================
  Files          15       15              
  Lines         890      892       +2     
  Branches      191      192       +1     
==========================================
+ Hits          728      730       +2     
  Misses        138      138              
  Partials       24       24              
```


| [Files Changed](https://app.codecov.io/gh/projectmesa/mesa/pull/1798?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=projectmesa) | Coverage Δ | |
|---|---|---|
| [mesa/experimental/jupyter\_viz.py](https://app.codecov.io/gh/projectmesa/mesa/pull/1798?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=projectmesa#diff-bWVzYS9leHBlcmltZW50YWwvanVweXRlcl92aXoucHk=) | `35.61% <100.00%> (+0.89%)` | :arrow_up: |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/projectmesa/mesa/pull/1798?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=projectmesa).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=projectmesa).


Patch:
diff --git a/mesa/experimental/jupyter_viz.py b/mesa/experimental/jupyter_viz.py
index a7eefb51..f2b95229 100644
--- a/mesa/experimental/jupyter_viz.py
+++ b/mesa/experimental/jupyter_viz.py
@@ -174,7 +174,7 @@ def check_param_is_fixed(param):
 def UserInputs(user_params, on_change=None):
     """Initialize user inputs for configurable model parameters.
     Currently supports :class:`solara.SliderInt`, :class:`solara.SliderFloat`,
-    and :class:`solara.Select`.
+    :class:`solara.Select`, and :class:`solara.Checkbox`.
 
     Props:
         user_params: dictionary with options for the input, including label,
@@ -215,6 +215,11 @@ def UserInputs(user_params, on_change=None):
                 on_value=change_handler,
                 values=options.get("values"),
             )
+        elif input_type == "Checkbox":
+            solara.Checkbox(
+                label=label,
+                value=options.get("value"),
+            )
         else:
             raise ValueError(f"{input_type} is not a supported input type")
 


Test patch:
diff --git a/tests/test_jupyter_viz.py b/tests/test_jupyter_viz.py
index f1d7371c..97021252 100644
--- a/tests/test_jupyter_viz.py
+++ b/tests/test_jupyter_viz.py
@@ -45,6 +45,19 @@ class TestMakeUserInput(unittest.TestCase):
         assert slider_int.max == options["max"]
         assert slider_int.step == options["step"]
 
+    def test_checkbox(self):
+        @solara.component
+        def Test(user_params):
+            UserInputs(user_params)
+
+        options = {"type": "Checkbox", "value": True, "label": "On"}
+        user_params = {"num_agents": options}
+        _, rc = solara.render(Test(user_params), handle_error=False)
+        checkbox = rc.find(vw.Checkbox).widget
+
+        assert checkbox.v_model == options["value"]
+        assert checkbox.label == options["label"]
+
     def test_label_fallback(self):
         """name should be used as fallback label"""