API Docs
Checkbox

Checkbox

The Checkbox class adds button in the Mercury sidebar.

import mercury as mr
 
# add checkbox
my_flag = mr.Checkbox(value=True, label="Switch me")
 
# read checkbox value
if my_flag.value:
    print("Checkbox is ON")
else:
    print("Checkbox is OFF")

Parameters

  • value (boolean) - the value of the checkbox, default is set to True.
  • label (string) - label of the checkbox.
  • url_key (string) - set this value if you would like to set Checkbox value with URL paramters.
  • disabled (boolean) - disable widget in the sidebar, default is set to False.
  • hidden (boolean) - hide widget in the sidebar, default is set to False.

Share widget value in URL

Let's create the Checkbox widget with url_key="flag":

import mercury as mr
 
# add checkbox
my_flag = mr.Checkbox(value=True, label="Switch me", url_key="flag")
 
# read checkbox value
if my_flag.value:
    print("Checkbox is ON")
else:
    print("Checkbox is OFF")

You can share the widgets values with other users. Please click the Share button in the sidebar bottom. It will open a dialog with URL.

The URL will look like:

https://your-server-address.com/app/notebook-name?flag=true

Please note that ?flag=true is added at the end of URL address.

Example App

Below is a screenshot with example app. Example app is available at docs.runmercury.com/app/checkbox (opens in a new tab).

App with checkbox widget