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)
Relevant Functions
-
ui.input_checkbox()
ui.input_checkbox(id, label, value=False, *, width=None)
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:
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.Supply values to
ui.input_checkbox()
’s first two parameters (id
andlabel
) to specify the id and label of the checkbox. Optionally, set thevalue
argument to eitherTrue
orFalse
to specify the initial value of the checkbox. By default, the checkbox has valueFalse
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:
- Use
input.<checkbox_id>()
(e.g.,input.checkbox()
) to access the value of a checkbox. The server value of a checkbox isTrue
if checked andFalse
if not checked.
See also: Checkbox Group(Checkbox