Checkbox Group
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
## file: app.py
from shiny import App, render, ui
app_ui = ui.page_fluid(
ui.input_checkbox_group(
"checkbox_group",
"Checkbox group",
{
"a": "A",
"b": "B",
"c": "C",
},
),
ui.output_text("value"),
{"class": "vh-100 d-flex align-items-center px-4"},
)
def server(input, output, session):
@output
@render.text
def value():
return ", ".join(input.checkbox_group())
app = App(app_ui, server)
from shiny import App, render, ui
app_ui = ui.page_fluid(
ui.input_checkbox_group(
"checkbox_group",
"Checkbox group",
{
"a": "A",
"b": "B",
"c": "C",
},
),
ui.output_text("value"),
)
def server(input, output, session):
@render.text
def value():
return ", ".join(input.checkbox_group())
app = App(app_ui, server)
Relevant Functions
-
ui.input_checkbox_group
ui.input_checkbox_group(id, label, choices, *, selected=None, inline=False, width=None)
Details
A checkbox group creates a group of checkboxes that can be used to toggle multiple choices independently.
Follow these steps to display a checkbox group in your app:
Add
ui.input_checkbox_group()
to the UI of your app to create a checkbox group. Where you call this function will determine where the checkbox group will appear within the app’s layout.Specify the
id
andlabel
parameters ofui.input_checkbox_group()
to define the identifier and label of the checkbox group.Supply the
choices
parameter with either a list or dictionary of choices. Ifchoices
is a list, its elements become the select list values and labels. Ifchoices
is a dictionary,ui.input_checkbox_group()
uses the dictionary keys as the checkbox values and the dictionary values as the checkbox labels.
The value of an input component is accessible as a reactive value within the server()
function. To access the value of a checkbox group:
- Use
input.<checkbox_group_id>()
(e.g.,input.checkbox_group()
) to access the value of a checkbox group. The server value of a checkbox group is a tuple of string(s) with the selected value(s).
See also: Checkbox