Skip to content

Selects and Tabs

In addition to top-level pages elements, you can include tabs and dropdown selects inside your reports using the dp.Select block. This allows users to switch between multiple blocks interactively and can even function as a basic filter. It is also useful for providing background context to another block - for instance, to add source code to a plot or a dataset.

The dp.Select block has two modes:

  • Tabs are used for less than 5 options - you can override this default by passing in the parameter type=dp.SelectType.TABS
  • Drop downs are used for 5 or more options - you can override this default by passing in the parametertype = dp.SelectType.DROPDOWN. In addition, a search bar will appear if the block contains more than 10 options.

To set the option names, make sure each block contained inside your dp.Select has a label.

Simple Tabs

import seaborn as sns
import altair as alt
import datapane as dp

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

report = dp.Report(
    "# Titanic overview",
    dp.HTML(
        '<html><img 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"></img></html>'
    ),
    dp.Select(
        blocks=[
            dp.Table(titanic.describe(), label="Data Description"),
            dp.DataTable(titanic, label="Whole Dataset"),
            dp.Code(code, label="Source code"),
        ]
    ),
)

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

titanic = sns.load_dataset("titanic")

report = dp.Report(
    "# Titanic overview",
    dp.HTML(
        '<html><img 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"></img></html>'
    ),
    dp.Select(
        blocks=[
            dp.Table(titanic.describe(), label="Data Description"),
            dp.DataTable(titanic, label="Whole Dataset"),
            dp.Code(code, label="Source code"),
        ]
    ),
)

report.save(path="simple-select.html")

Simple Dropdown

import seaborn as sns
import altair as alt
import datapane as dp

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

report = dp.Report(
    "# Titanic overview",
    dp.HTML(
        '<html><img 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"></img></html>'
    ),
    dp.Select(
        blocks=[
            dp.Table(titanic.describe(), label="Data Description"),
            dp.DataTable(titanic, label="Whole Dataset"),
            dp.Code(code, label="Source code"),
        ]
    ),
)

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

titanic = sns.load_dataset("titanic")

report = dp.Report(
    "# Titanic overview",
    dp.HTML(
        '<html><img 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"></img></html>'
    ),
    dp.Select(
        blocks=[
            dp.Table(titanic.describe(), label="Data Description"),
            dp.DataTable(titanic, label="Whole Dataset"),
            dp.Code(code, label="Source code"),
        ],
        type=dp.SelectType.DROPDOWN,
    ),
)

report.save(path="select-dropdown.html")