Checkbox

#| standalone: true
#| components: [viewer]
#| viewerHeight: 150

## file: app.py
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.row(
        ui.column(
            6,
            ui.input_checkbox("checkbox", "Checkbox", True).add_class(
                "mb-0 text-center"
            ),
        ),
        ui.column(6, ui.output_ui("value").add_class("mb-0 text-center")),
        {"class": "vh-100 justify-content-center align-items-center px-5"},
    )
)

def server(input, output, session):
    @render.ui
    def value():
        return input.checkbox()

app = App(app_ui, server)
from shiny import render
from shiny.express import input, ui

ui.input_checkbox("checkbox", "Checkbox", False)  

@render.ui
def value():
    return input.checkbox()
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_checkbox("checkbox", "Checkbox", False),  
    ui.output_ui("value"),
)

def server(input, output, session):
    @render.ui
    def value():
        return input.checkbox()

app = App(app_ui, server)
No matching items

Relevant Functions

No matching items

Details

A checkbox creates a single checkbox that can be used to specify logical values.

Follow these steps to add a checkbox to your app:

  1. Add ui.input_checkbox() to the UI of your app to create a checkbox. Where you call this function will determine where the checkbox will appear within the app’s layout.

  2. Supply values to ui.input_checkbox()’s first two parameters (id and label) to specify the id and label of the checkbox. Optionally, set the value argument to either True or False to specify the initial value of the checkbox. By default, the checkbox has value False and is un-checked.

The value of an input component is accessible as a reactive value within the server() function. To access the value of a checkbox:

  1. Use input.<checkbox_id>() (e.g., input.checkbox()) to access the value of a checkbox. The server value of a checkbox is True if checked and False if not checked.

See also: Checkbox Group(Checkbox