We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Implement label_visibility with Checkbox
### Problem

Streamlit 1.13.0 released with `label_visibility`, but noticeably missing is the checkbox. The feature was designed to work with vertical alignment of widgets which have no impact on the checkbox. There may be reasons to have that.

### Solution

**MVP:** Users can continue to add `""`, but the checkbox is not accessible, and there may be unnecessary spacing.

**Preferred solution:** Add `label_visibility` to checkboxes.

### Additional context

Add any other context or screenshots about the feature request here. For example, did this FR come from https://discuss.streamlit.io or another site? Link the original source here!

---

Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

**If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.**


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `e2e/scripts/st_checkbox.py`
Content:
```
1 # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import streamlit as st
16 from streamlit import runtime
17 
18 i1 = st.checkbox("checkbox 1", True)
19 st.write("value 1:", i1)
20 
21 i2 = st.checkbox("checkbox 2", False)
22 st.write("value 2:", i2)
23 
24 i3 = st.checkbox("checkbox 3")
25 st.write("value 3:", i3)
26 
27 if runtime.exists():
28 
29     def on_change():
30         st.session_state.checkbox_clicked = True
31 
32     st.checkbox("checkbox 4", key="checkbox4", on_change=on_change)
33     st.write("value 4:", st.session_state.checkbox4)
34     st.write("checkbox clicked:", "checkbox_clicked" in st.session_state)
35 
36 i5 = st.checkbox("checkbox 5", disabled=True)
37 st.write("value 5:", i5)
38 
39 i6 = st.checkbox("checkbox 6", value=True, disabled=True)
40 st.write("value 6:", i6)
41
```

Path: `lib/streamlit/elements/checkbox.py`
Content:
```
1 # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from dataclasses import dataclass
16 from textwrap import dedent
17 from typing import TYPE_CHECKING, Optional, cast
18 
19 from streamlit.elements.form import current_form_id
20 from streamlit.elements.utils import check_callback_rules, check_session_state_rules
21 from streamlit.proto.Checkbox_pb2 import Checkbox as CheckboxProto
22 from streamlit.runtime.metrics_util import gather_metrics
23 from streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx
24 from streamlit.runtime.state import (
25     WidgetArgs,
26     WidgetCallback,
27     WidgetKwargs,
28     register_widget,
29 )
30 from streamlit.type_util import Key, to_key
31 
32 if TYPE_CHECKING:
33     from streamlit.delta_generator import DeltaGenerator
34 
35 
36 @dataclass
37 class CheckboxSerde:
38     value: bool
39 
40     def serialize(self, v: bool) -> bool:
41         return bool(v)
42 
43     def deserialize(self, ui_value: Optional[bool], widget_id: str = "") -> bool:
44         return bool(ui_value if ui_value is not None else self.value)
45 
46 
47 class CheckboxMixin:
48     @gather_metrics("checkbox")
49     def checkbox(
50         self,
51         label: str,
52         value: bool = False,
53         key: Optional[Key] = None,
54         help: Optional[str] = None,
55         on_change: Optional[WidgetCallback] = None,
56         args: Optional[WidgetArgs] = None,
57         kwargs: Optional[WidgetKwargs] = None,
58         *,  # keyword-only arguments:
59         disabled: bool = False,
60     ) -> bool:
61         """Display a checkbox widget.
62 
63         Parameters
64         ----------
65         label : str
66             A short label explaining to the user what this checkbox is for.
67             The label can optionally contain Markdown and supports the following
68             elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.
69         value : bool
70             Preselect the checkbox when it first renders. This will be
71             cast to bool internally.
72         key : str or int
73             An optional string or integer to use as the unique key for the widget.
74             If this is omitted, a key will be generated for the widget
75             based on its content. Multiple widgets of the same type may
76             not share the same key.
77         help : str
78             An optional tooltip that gets displayed next to the checkbox.
79         on_change : callable
80             An optional callback invoked when this checkbox's value changes.
81         args : tuple
82             An optional tuple of args to pass to the callback.
83         kwargs : dict
84             An optional dict of kwargs to pass to the callback.
85         disabled : bool
86             An optional boolean, which disables the checkbox if set to True.
87             The default is False. This argument can only be supplied by keyword.
88 
89         Returns
90         -------
91         bool
92             Whether or not the checkbox is checked.
93 
94         Example
95         -------
96         >>> import streamlit as st
97         >>> agree = st.checkbox('I agree')
98         >>>
99         >>> if agree:
100         ...     st.write('Great!')
101 
102         .. output::
103            https://doc-checkbox.streamlitapp.com/
104            height: 220px
105 
106         """
107         ctx = get_script_run_ctx()
108         return self._checkbox(
109             label=label,
110             value=value,
111             key=key,
112             help=help,
113             on_change=on_change,
114             args=args,
115             kwargs=kwargs,
116             disabled=disabled,
117             ctx=ctx,
118         )
119 
120     def _checkbox(
121         self,
122         label: str,
123         value: bool = False,
124         key: Optional[Key] = None,
125         help: Optional[str] = None,
126         on_change: Optional[WidgetCallback] = None,
127         args: Optional[WidgetArgs] = None,
128         kwargs: Optional[WidgetKwargs] = None,
129         *,  # keyword-only arguments:
130         disabled: bool = False,
131         ctx: Optional[ScriptRunContext] = None,
132     ) -> bool:
133         key = to_key(key)
134         check_callback_rules(self.dg, on_change)
135         check_session_state_rules(
136             default_value=None if value is False else value, key=key
137         )
138 
139         checkbox_proto = CheckboxProto()
140         checkbox_proto.label = label
141         checkbox_proto.default = bool(value)
142         checkbox_proto.form_id = current_form_id(self.dg)
143         if help is not None:
144             checkbox_proto.help = dedent(help)
145 
146         serde = CheckboxSerde(value)
147 
148         checkbox_state = register_widget(
149             "checkbox",
150             checkbox_proto,
151             user_key=key,
152             on_change_handler=on_change,
153             args=args,
154             kwargs=kwargs,
155             deserializer=serde.deserialize,
156             serializer=serde.serialize,
157             ctx=ctx,
158         )
159 
160         # This needs to be done after register_widget because we don't want
161         # the following proto fields to affect a widget's ID.
162         checkbox_proto.disabled = disabled
163         if checkbox_state.value_changed:
164             checkbox_proto.value = checkbox_state.value
165             checkbox_proto.set_value = True
166 
167         self.dg._enqueue("checkbox", checkbox_proto)
168         return checkbox_state.value
169 
170     @property
171     def dg(self) -> "DeltaGenerator":
172         """Get our DeltaGenerator."""
173         return cast("DeltaGenerator", self)
174
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/e2e/scripts/st_checkbox.py b/e2e/scripts/st_checkbox.py
--- a/e2e/scripts/st_checkbox.py
+++ b/e2e/scripts/st_checkbox.py
@@ -38,3 +38,9 @@
 
 i6 = st.checkbox("checkbox 6", value=True, disabled=True)
 st.write("value 6:", i6)
+
+i7 = st.checkbox("checkbox 7", label_visibility="hidden")
+st.write("value 7:", i7)
+
+i8 = st.checkbox("checkbox 8", label_visibility="collapsed")
+st.write("value 8:", i8)
diff --git a/lib/streamlit/elements/checkbox.py b/lib/streamlit/elements/checkbox.py
--- a/lib/streamlit/elements/checkbox.py
+++ b/lib/streamlit/elements/checkbox.py
@@ -17,7 +17,11 @@
 from typing import TYPE_CHECKING, Optional, cast
 
 from streamlit.elements.form import current_form_id
-from streamlit.elements.utils import check_callback_rules, check_session_state_rules
+from streamlit.elements.utils import (
+    check_callback_rules,
+    check_session_state_rules,
+    get_label_visibility_proto_value,
+)
 from streamlit.proto.Checkbox_pb2 import Checkbox as CheckboxProto
 from streamlit.runtime.metrics_util import gather_metrics
 from streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx
@@ -27,7 +31,7 @@
     WidgetKwargs,
     register_widget,
 )
-from streamlit.type_util import Key, to_key
+from streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings, to_key
 
 if TYPE_CHECKING:
     from streamlit.delta_generator import DeltaGenerator
@@ -57,6 +61,7 @@
         kwargs: Optional[WidgetKwargs] = None,
         *,  # keyword-only arguments:
         disabled: bool = False,
+        label_visibility: LabelVisibility = "visible",
     ) -> bool:
         """Display a checkbox widget.
 
@@ -85,6 +90,11 @@
         disabled : bool
             An optional boolean, which disables the checkbox if set to True.
             The default is False. This argument can only be supplied by keyword.
+        label_visibility : "visible" or "hidden" or "collapsed"
+            The visibility of the label. If "hidden", the label doesn't show but there
+            is still empty space for it (equivalent to label="").
+            If "collapsed", both the label and the space are removed. Default is
+            "visible". This argument can only be supplied by keyword.
 
         Returns
         -------
@@ -114,6 +124,7 @@
             args=args,
             kwargs=kwargs,
             disabled=disabled,
+            label_visibility=label_visibility,
             ctx=ctx,
         )
 
@@ -128,6 +139,7 @@
         kwargs: Optional[WidgetKwargs] = None,
         *,  # keyword-only arguments:
         disabled: bool = False,
+        label_visibility: LabelVisibility = "visible",
         ctx: Optional[ScriptRunContext] = None,
     ) -> bool:
         key = to_key(key)
@@ -136,6 +148,8 @@
             default_value=None if value is False else value, key=key
         )
 
+        maybe_raise_label_warnings(label, label_visibility)
+
         checkbox_proto = CheckboxProto()
         checkbox_proto.label = label
         checkbox_proto.default = bool(value)
@@ -160,6 +174,10 @@
         # This needs to be done after register_widget because we don't want
         # the following proto fields to affect a widget's ID.
         checkbox_proto.disabled = disabled
+        checkbox_proto.label_visibility.value = get_label_visibility_proto_value(
+            label_visibility
+        )
+
         if checkbox_state.value_changed:
             checkbox_proto.value = checkbox_state.value
             checkbox_proto.set_value = True

{"golden_diff": "diff --git a/e2e/scripts/st_checkbox.py b/e2e/scripts/st_checkbox.py\n--- a/e2e/scripts/st_checkbox.py\n+++ b/e2e/scripts/st_checkbox.py\n@@ -38,3 +38,9 @@\n \n i6 = st.checkbox(\"checkbox 6\", value=True, disabled=True)\n st.write(\"value 6:\", i6)\n+\n+i7 = st.checkbox(\"checkbox 7\", label_visibility=\"hidden\")\n+st.write(\"value 7:\", i7)\n+\n+i8 = st.checkbox(\"checkbox 8\", label_visibility=\"collapsed\")\n+st.write(\"value 8:\", i8)\ndiff --git a/lib/streamlit/elements/checkbox.py b/lib/streamlit/elements/checkbox.py\n--- a/lib/streamlit/elements/checkbox.py\n+++ b/lib/streamlit/elements/checkbox.py\n@@ -17,7 +17,11 @@\n from typing import TYPE_CHECKING, Optional, cast\n \n from streamlit.elements.form import current_form_id\n-from streamlit.elements.utils import check_callback_rules, check_session_state_rules\n+from streamlit.elements.utils import (\n+    check_callback_rules,\n+    check_session_state_rules,\n+    get_label_visibility_proto_value,\n+)\n from streamlit.proto.Checkbox_pb2 import Checkbox as CheckboxProto\n from streamlit.runtime.metrics_util import gather_metrics\n from streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx\n@@ -27,7 +31,7 @@\n     WidgetKwargs,\n     register_widget,\n )\n-from streamlit.type_util import Key, to_key\n+from streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings, to_key\n \n if TYPE_CHECKING:\n     from streamlit.delta_generator import DeltaGenerator\n@@ -57,6 +61,7 @@\n         kwargs: Optional[WidgetKwargs] = None,\n         *,  # keyword-only arguments:\n         disabled: bool = False,\n+        label_visibility: LabelVisibility = \"visible\",\n     ) -> bool:\n         \"\"\"Display a checkbox widget.\n \n@@ -85,6 +90,11 @@\n         disabled : bool\n             An optional boolean, which disables the checkbox if set to True.\n             The default is False. This argument can only be supplied by keyword.\n+        label_visibility : \"visible\" or \"hidden\" or \"collapsed\"\n+            The visibility of the label. If \"hidden\", the label doesn't show but there\n+            is still empty space for it (equivalent to label=\"\").\n+            If \"collapsed\", both the label and the space are removed. Default is\n+            \"visible\". This argument can only be supplied by keyword.\n \n         Returns\n         -------\n@@ -114,6 +124,7 @@\n             args=args,\n             kwargs=kwargs,\n             disabled=disabled,\n+            label_visibility=label_visibility,\n             ctx=ctx,\n         )\n \n@@ -128,6 +139,7 @@\n         kwargs: Optional[WidgetKwargs] = None,\n         *,  # keyword-only arguments:\n         disabled: bool = False,\n+        label_visibility: LabelVisibility = \"visible\",\n         ctx: Optional[ScriptRunContext] = None,\n     ) -> bool:\n         key = to_key(key)\n@@ -136,6 +148,8 @@\n             default_value=None if value is False else value, key=key\n         )\n \n+        maybe_raise_label_warnings(label, label_visibility)\n+\n         checkbox_proto = CheckboxProto()\n         checkbox_proto.label = label\n         checkbox_proto.default = bool(value)\n@@ -160,6 +174,10 @@\n         # This needs to be done after register_widget because we don't want\n         # the following proto fields to affect a widget's ID.\n         checkbox_proto.disabled = disabled\n+        checkbox_proto.label_visibility.value = get_label_visibility_proto_value(\n+            label_visibility\n+        )\n+\n         if checkbox_state.value_changed:\n             checkbox_proto.value = checkbox_state.value\n             checkbox_proto.set_value = True\n", "issue": "Implement label_visibility with Checkbox\n### Problem\r\n\r\nStreamlit 1.13.0 released with `label_visibility`, but noticeably missing is the checkbox. The feature was designed to work with vertical alignment of widgets which have no impact on the checkbox. There may be reasons to have that.\r\n\r\n### Solution\r\n\r\n**MVP:** Users can continue to add `\"\"`, but the checkbox is not accessible, and there may be unnecessary spacing.\r\n\r\n**Preferred solution:** Add `label_visibility` to checkboxes.\r\n\r\n### Additional context\r\n\r\nAdd any other context or screenshots about the feature request here. For example, did this FR come from https://discuss.streamlit.io or another site? Link the original source here!\r\n\r\n---\r\n\r\nCommunity voting on feature requests enables the Streamlit team to understand which features are most important to our users.\r\n\r\n**If you'd like the Streamlit team to prioritize this feature request, please use the \ud83d\udc4d (thumbs up emoji) reaction in response to the initial post.**\r\n\n", "before_files": [{"content": "# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport streamlit as st\nfrom streamlit import runtime\n\ni1 = st.checkbox(\"checkbox 1\", True)\nst.write(\"value 1:\", i1)\n\ni2 = st.checkbox(\"checkbox 2\", False)\nst.write(\"value 2:\", i2)\n\ni3 = st.checkbox(\"checkbox 3\")\nst.write(\"value 3:\", i3)\n\nif runtime.exists():\n\n    def on_change():\n        st.session_state.checkbox_clicked = True\n\n    st.checkbox(\"checkbox 4\", key=\"checkbox4\", on_change=on_change)\n    st.write(\"value 4:\", st.session_state.checkbox4)\n    st.write(\"checkbox clicked:\", \"checkbox_clicked\" in st.session_state)\n\ni5 = st.checkbox(\"checkbox 5\", disabled=True)\nst.write(\"value 5:\", i5)\n\ni6 = st.checkbox(\"checkbox 6\", value=True, disabled=True)\nst.write(\"value 6:\", i6)\n", "path": "e2e/scripts/st_checkbox.py"}, {"content": "# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom dataclasses import dataclass\nfrom textwrap import dedent\nfrom typing import TYPE_CHECKING, Optional, cast\n\nfrom streamlit.elements.form import current_form_id\nfrom streamlit.elements.utils import check_callback_rules, check_session_state_rules\nfrom streamlit.proto.Checkbox_pb2 import Checkbox as CheckboxProto\nfrom streamlit.runtime.metrics_util import gather_metrics\nfrom streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx\nfrom streamlit.runtime.state import (\n    WidgetArgs,\n    WidgetCallback,\n    WidgetKwargs,\n    register_widget,\n)\nfrom streamlit.type_util import Key, to_key\n\nif TYPE_CHECKING:\n    from streamlit.delta_generator import DeltaGenerator\n\n\n@dataclass\nclass CheckboxSerde:\n    value: bool\n\n    def serialize(self, v: bool) -> bool:\n        return bool(v)\n\n    def deserialize(self, ui_value: Optional[bool], widget_id: str = \"\") -> bool:\n        return bool(ui_value if ui_value is not None else self.value)\n\n\nclass CheckboxMixin:\n    @gather_metrics(\"checkbox\")\n    def checkbox(\n        self,\n        label: str,\n        value: bool = False,\n        key: Optional[Key] = None,\n        help: Optional[str] = None,\n        on_change: Optional[WidgetCallback] = None,\n        args: Optional[WidgetArgs] = None,\n        kwargs: Optional[WidgetKwargs] = None,\n        *,  # keyword-only arguments:\n        disabled: bool = False,\n    ) -> bool:\n        \"\"\"Display a checkbox widget.\n\n        Parameters\n        ----------\n        label : str\n            A short label explaining to the user what this checkbox is for.\n            The label can optionally contain Markdown and supports the following\n            elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.\n        value : bool\n            Preselect the checkbox when it first renders. This will be\n            cast to bool internally.\n        key : str or int\n            An optional string or integer to use as the unique key for the widget.\n            If this is omitted, a key will be generated for the widget\n            based on its content. Multiple widgets of the same type may\n            not share the same key.\n        help : str\n            An optional tooltip that gets displayed next to the checkbox.\n        on_change : callable\n            An optional callback invoked when this checkbox's value changes.\n        args : tuple\n            An optional tuple of args to pass to the callback.\n        kwargs : dict\n            An optional dict of kwargs to pass to the callback.\n        disabled : bool\n            An optional boolean, which disables the checkbox if set to True.\n            The default is False. This argument can only be supplied by keyword.\n\n        Returns\n        -------\n        bool\n            Whether or not the checkbox is checked.\n\n        Example\n        -------\n        >>> import streamlit as st\n        >>> agree = st.checkbox('I agree')\n        >>>\n        >>> if agree:\n        ...     st.write('Great!')\n\n        .. output::\n           https://doc-checkbox.streamlitapp.com/\n           height: 220px\n\n        \"\"\"\n        ctx = get_script_run_ctx()\n        return self._checkbox(\n            label=label,\n            value=value,\n            key=key,\n            help=help,\n            on_change=on_change,\n            args=args,\n            kwargs=kwargs,\n            disabled=disabled,\n            ctx=ctx,\n        )\n\n    def _checkbox(\n        self,\n        label: str,\n        value: bool = False,\n        key: Optional[Key] = None,\n        help: Optional[str] = None,\n        on_change: Optional[WidgetCallback] = None,\n        args: Optional[WidgetArgs] = None,\n        kwargs: Optional[WidgetKwargs] = None,\n        *,  # keyword-only arguments:\n        disabled: bool = False,\n        ctx: Optional[ScriptRunContext] = None,\n    ) -> bool:\n        key = to_key(key)\n        check_callback_rules(self.dg, on_change)\n        check_session_state_rules(\n            default_value=None if value is False else value, key=key\n        )\n\n        checkbox_proto = CheckboxProto()\n        checkbox_proto.label = label\n        checkbox_proto.default = bool(value)\n        checkbox_proto.form_id = current_form_id(self.dg)\n        if help is not None:\n            checkbox_proto.help = dedent(help)\n\n        serde = CheckboxSerde(value)\n\n        checkbox_state = register_widget(\n            \"checkbox\",\n            checkbox_proto,\n            user_key=key,\n            on_change_handler=on_change,\n            args=args,\n            kwargs=kwargs,\n            deserializer=serde.deserialize,\n            serializer=serde.serialize,\n            ctx=ctx,\n        )\n\n        # This needs to be done after register_widget because we don't want\n        # the following proto fields to affect a widget's ID.\n        checkbox_proto.disabled = disabled\n        if checkbox_state.value_changed:\n            checkbox_proto.value = checkbox_state.value\n            checkbox_proto.set_value = True\n\n        self.dg._enqueue(\"checkbox\", checkbox_proto)\n        return checkbox_state.value\n\n    @property\n    def dg(self) -> \"DeltaGenerator\":\n        \"\"\"Get our DeltaGenerator.\"\"\"\n        return cast(\"DeltaGenerator\", self)\n", "path": "lib/streamlit/elements/checkbox.py"}], "after_files": [{"content": "# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport streamlit as st\nfrom streamlit import runtime\n\ni1 = st.checkbox(\"checkbox 1\", True)\nst.write(\"value 1:\", i1)\n\ni2 = st.checkbox(\"checkbox 2\", False)\nst.write(\"value 2:\", i2)\n\ni3 = st.checkbox(\"checkbox 3\")\nst.write(\"value 3:\", i3)\n\nif runtime.exists():\n\n    def on_change():\n        st.session_state.checkbox_clicked = True\n\n    st.checkbox(\"checkbox 4\", key=\"checkbox4\", on_change=on_change)\n    st.write(\"value 4:\", st.session_state.checkbox4)\n    st.write(\"checkbox clicked:\", \"checkbox_clicked\" in st.session_state)\n\ni5 = st.checkbox(\"checkbox 5\", disabled=True)\nst.write(\"value 5:\", i5)\n\ni6 = st.checkbox(\"checkbox 6\", value=True, disabled=True)\nst.write(\"value 6:\", i6)\n\ni7 = st.checkbox(\"checkbox 7\", label_visibility=\"hidden\")\nst.write(\"value 7:\", i7)\n\ni8 = st.checkbox(\"checkbox 8\", label_visibility=\"collapsed\")\nst.write(\"value 8:\", i8)\n", "path": "e2e/scripts/st_checkbox.py"}, {"content": "# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom dataclasses import dataclass\nfrom textwrap import dedent\nfrom typing import TYPE_CHECKING, Optional, cast\n\nfrom streamlit.elements.form import current_form_id\nfrom streamlit.elements.utils import (\n    check_callback_rules,\n    check_session_state_rules,\n    get_label_visibility_proto_value,\n)\nfrom streamlit.proto.Checkbox_pb2 import Checkbox as CheckboxProto\nfrom streamlit.runtime.metrics_util import gather_metrics\nfrom streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx\nfrom streamlit.runtime.state import (\n    WidgetArgs,\n    WidgetCallback,\n    WidgetKwargs,\n    register_widget,\n)\nfrom streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings, to_key\n\nif TYPE_CHECKING:\n    from streamlit.delta_generator import DeltaGenerator\n\n\n@dataclass\nclass CheckboxSerde:\n    value: bool\n\n    def serialize(self, v: bool) -> bool:\n        return bool(v)\n\n    def deserialize(self, ui_value: Optional[bool], widget_id: str = \"\") -> bool:\n        return bool(ui_value if ui_value is not None else self.value)\n\n\nclass CheckboxMixin:\n    @gather_metrics(\"checkbox\")\n    def checkbox(\n        self,\n        label: str,\n        value: bool = False,\n        key: Optional[Key] = None,\n        help: Optional[str] = None,\n        on_change: Optional[WidgetCallback] = None,\n        args: Optional[WidgetArgs] = None,\n        kwargs: Optional[WidgetKwargs] = None,\n        *,  # keyword-only arguments:\n        disabled: bool = False,\n        label_visibility: LabelVisibility = \"visible\",\n    ) -> bool:\n        \"\"\"Display a checkbox widget.\n\n        Parameters\n        ----------\n        label : str\n            A short label explaining to the user what this checkbox is for.\n            The label can optionally contain Markdown and supports the following\n            elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.\n        value : bool\n            Preselect the checkbox when it first renders. This will be\n            cast to bool internally.\n        key : str or int\n            An optional string or integer to use as the unique key for the widget.\n            If this is omitted, a key will be generated for the widget\n            based on its content. Multiple widgets of the same type may\n            not share the same key.\n        help : str\n            An optional tooltip that gets displayed next to the checkbox.\n        on_change : callable\n            An optional callback invoked when this checkbox's value changes.\n        args : tuple\n            An optional tuple of args to pass to the callback.\n        kwargs : dict\n            An optional dict of kwargs to pass to the callback.\n        disabled : bool\n            An optional boolean, which disables the checkbox if set to True.\n            The default is False. This argument can only be supplied by keyword.\n        label_visibility : \"visible\" or \"hidden\" or \"collapsed\"\n            The visibility of the label. If \"hidden\", the label doesn't show but there\n            is still empty space for it (equivalent to label=\"\").\n            If \"collapsed\", both the label and the space are removed. Default is\n            \"visible\". This argument can only be supplied by keyword.\n\n        Returns\n        -------\n        bool\n            Whether or not the checkbox is checked.\n\n        Example\n        -------\n        >>> import streamlit as st\n        >>> agree = st.checkbox('I agree')\n        >>>\n        >>> if agree:\n        ...     st.write('Great!')\n\n        .. output::\n           https://doc-checkbox.streamlitapp.com/\n           height: 220px\n\n        \"\"\"\n        ctx = get_script_run_ctx()\n        return self._checkbox(\n            label=label,\n            value=value,\n            key=key,\n            help=help,\n            on_change=on_change,\n            args=args,\n            kwargs=kwargs,\n            disabled=disabled,\n            label_visibility=label_visibility,\n            ctx=ctx,\n        )\n\n    def _checkbox(\n        self,\n        label: str,\n        value: bool = False,\n        key: Optional[Key] = None,\n        help: Optional[str] = None,\n        on_change: Optional[WidgetCallback] = None,\n        args: Optional[WidgetArgs] = None,\n        kwargs: Optional[WidgetKwargs] = None,\n        *,  # keyword-only arguments:\n        disabled: bool = False,\n        label_visibility: LabelVisibility = \"visible\",\n        ctx: Optional[ScriptRunContext] = None,\n    ) -> bool:\n        key = to_key(key)\n        check_callback_rules(self.dg, on_change)\n        check_session_state_rules(\n            default_value=None if value is False else value, key=key\n        )\n\n        maybe_raise_label_warnings(label, label_visibility)\n\n        checkbox_proto = CheckboxProto()\n        checkbox_proto.label = label\n        checkbox_proto.default = bool(value)\n        checkbox_proto.form_id = current_form_id(self.dg)\n        if help is not None:\n            checkbox_proto.help = dedent(help)\n\n        serde = CheckboxSerde(value)\n\n        checkbox_state = register_widget(\n            \"checkbox\",\n            checkbox_proto,\n            user_key=key,\n            on_change_handler=on_change,\n            args=args,\n            kwargs=kwargs,\n            deserializer=serde.deserialize,\n            serializer=serde.serialize,\n            ctx=ctx,\n        )\n\n        # This needs to be done after register_widget because we don't want\n        # the following proto fields to affect a widget's ID.\n        checkbox_proto.disabled = disabled\n        checkbox_proto.label_visibility.value = get_label_visibility_proto_value(\n            label_visibility\n        )\n\n        if checkbox_state.value_changed:\n            checkbox_proto.value = checkbox_state.value\n            checkbox_proto.set_value = True\n\n        self.dg._enqueue(\"checkbox\", checkbox_proto)\n        return checkbox_state.value\n\n    @property\n    def dg(self) -> \"DeltaGenerator\":\n        \"\"\"Get our DeltaGenerator.\"\"\"\n        return cast(\"DeltaGenerator\", self)\n", "path": "lib/streamlit/elements/checkbox.py"}]}