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 render
from shiny.express import input, ui

ui.input_checkbox_group(  
    "checkbox_group",  
    "Checkbox group",  
    {  
        "a": "A",  
        "b": "B",  
        "c": "C",  
    },  
)  

@render.text
def value():
    return ", ".join(input.checkbox_group())
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)
No matching items

Relevant Functions

No matching items

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:

  1. 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.

  2. Specify the id and label parameters of ui.input_checkbox_group() to define the identifier and label of the checkbox group.

  3. Supply the choices parameter with either a list or dictionary of choices. If choices is a list, its elements become the select list values and labels. If choices 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:

  1. 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