Skip to content

Toggle

Toggle

Toggles act as a container that holds a list of nested Block objects, whose visibility can be toggled on or off by the report viewer

Parameters:

Name Type Description Default
*arg_blocks BlockOrPrimitive

Group to add to report

()
blocks List[BlockOrPrimitive]

Allows providing the report blocks as a single list

None
name BlockId

A unique id for the blocks to aid querying (optional)

None
label str

A label used when displaying the block (optional)

None

report_minimum_blocks = 1 class-attribute instance-attribute

Simple Toggle

import seaborn as sns
import altair as alt

code = """
titanic = sns.load_dataset("titanic")

app = dp.App(
    "# Titanic overview",
    dp.HTML(
        '<html><img alt="No description has been provided for this image" src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/RMS_Titanic_3.jpg/1599px-RMS_Titanic_3.jpg" style="height:400px;display:flex;margin:auto"/></html>'
    ),
    dp.Select(
        blocks=[
            dp.Table(titanic.describe(), label="Data Description"),
            dp.DataTable(titanic, label="Whole Dataset"),
            dp.Code(code, label="Source code"),
        ]
    ),
)

app.save(path="select.html")
"""

titanic = sns.load_dataset("titanic")

dp.Blocks(
    "# Titanic overview",
    dp.HTML(
        '<html><img alt="No description has been provided for this image" src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/RMS_Titanic_3.jpg/1599px-RMS_Titanic_3.jpg" style="height:400px;display:flex;margin:auto"/></html>'
    ),
    dp.Toggle(
        blocks=[
            dp.Table(titanic.describe(), label="Data Description"),
            dp.DataTable(titanic, label="Whole Dataset"),
            dp.Code(code, label="Source code"),
        ]
    ),
)