Skip to content

Actions

vizro.actions

Built-in actions, typically aliased as va using import vizro.actions as va.

Usage documentation

How to use actions

export_data

Exports data of target charts, tables and figures.

Usage documentation

How to export data

Parameters:

  • targets (list[ModelID]) –

    List of target component ids for which to download data. If none are given then download data from all components on the page.

  • file_format (Literal['csv', 'xlsx']) –

    Format of downloaded files. Defaults to "csv".

Example
import vizro.actions as va

vm.Button(
    text="Export data",
    actions=va.export_data(targets=["graph_id", "table_id"], file_format="xlsx"),
)

filter_interaction deprecated

Deprecated

filter_interaction is deprecated and will not exist in Vizro 0.2.0. Use the more powerful and flexible [set_control][vizro.actions.set_control].

Filters targeted graph, tables and figures when a source graph or table is clicked.

Parameters:

  • targets (list[ModelID]) –

    Target component to be affected by filter. If none are given then target all valid components on the page.

set_control

Sets the value of a control, which then updates its targets.

Usage documentation

Graph and table interactions

The following Vizro models can be a source of set_control:

  • [AgGrid][vizro.models.AgGrid]: triggers set_control when user clicks on a row in the table. value is string specifying which column in the clicked row is used to set control.
  • [Graph][vizro.models.Graph]: triggers set_control when user clicks on data in the graph. value is string that can be used in two ways to specify how to set control:

    • Column from which to take the value. This requires you to set custom_data in the graph's figure function.
    • String to traverse a Box that contains the trigger data clickData["points"][0]. This is typically useful for a positional variable, for example "x", and does not require setting custom_data.
  • [Figure][vizro.models.Figure]: triggers set_control when user clicks on the figure. value specifies a literal value to set control to.

  • [Button][vizro.models.Button]: triggers set_control when user clicks on the button. value specifies a literal value to set control to.
  • [Card][vizro.models.Card]: triggers set_control when user clicks on the card. value specifies a literal value to set control to.

Parameters:

  • control (ModelID) –

    Control whose value is set. If this is on a different page from the trigger then it must have show_in_url=True. The control's selector must be categorical (e.g. Dropdown, RadioItems, Checklist).

  • value (JsonValue) –

    Value taken from trigger to set control. Format depends on the source model that triggers set_control.

AgGrid as trigger
import vizro.actions as va

vm.AgGrid(
    figure=dash_ag_grid(iris),
    actions=va.set_control(control="target_control", value="species"),
)
Graph as trigger with custom_data
import vizro.actions as va

vm.Graph(
    figure=px.scatter(iris, x="sepal_width", y="sepal_length", custom_data="species"),
    actions=va.set_control(control="target_control", value="species"),
)
Graph as trigger without custom_data
import vizro.actions as va

vm.Graph(
    figure=px.box(iris, x="species", y="sepal_length"),
    actions=va.set_control(control="target_control", value="x"),
)
Figure as trigger
import vizro.actions as va
from vizro.figures import kpi_card

vm.Figure(
    figure=kpi_card(tips, value_column="tip", title="Click KPI to set control to A"),
    actions=va.set_control(control="target_control", value="A"),
)
Button as trigger
import vizro.actions as va

vm.Button(
    text="Click to set control to A",
    actions=va.set_control(control="target_control", value="A"),
)
Card as trigger
import vizro.actions as va

vm.Card(
    title="Click Card to set control to A",
    actions=va.set_control(control="target_control", value="A"),
)

show_notification

Shows a notification message.

Usage documentation

Notifications

Parameters:

  • text (str) –

    Markdown text for the main notification message. Follows the CommonMark specification.

  • variant (Literal['info', 'success', 'warning', 'error', 'progress']) –

    Variant that determines color and default icon. If progress, the notification will show a loading spinner instead of an icon. Defaults to "info".

  • title (str) –

    Notification title. Set to "" to hide the title. Defaults to the capitalized variant name, for example "Info" for variant="info".

  • icon (str) –

    Icon name from the Google Material Icon Library. Ignored if variant="progress". Defaults to the variant-specific icon, for example 'info' for 'info' variant.

  • auto_close (bool | int) –

    Auto-close duration in milliseconds. Set to False to keep the notification open until the user closes it manually. Default value depends on variant: 4000 for info/success/warning/error, False for progress.

Example
import vizro.actions as va
import vizro.models as vm

vm.Button(
    text="Save",
    actions=va.show_notification(
        title="Useful information",
        text="This is some useful information that you should know.",
    ),
)

update_notification

Updates an existing notification message.

This action updates notifications that were previously created with [show_notification][vizro.actions.show_notification]. notification must match the id of the original show_notification action.

Usage documentation

Update notification

Parameters:

  • notification (ModelID) –

    Notification to update. Must match the id of the original show_notification action.

  • text (str) –

    Markdown text for the main notification message. Follows the CommonMark specification.

  • variant (Literal['info', 'success', 'warning', 'error', 'progress']) –

    Variant that determines color and default icon. If progress, the notification will show a loading spinner instead of an icon. Defaults to "info".

  • title (str) –

    Notification title. Set to "" to hide the title. Defaults to the capitalized variant name, for example "Info" for variant="info".

  • icon (str) –

    Icon name from the Google Material Icon Library. Ignored if variant="progress". Defaults to the variant-specific icon, for example 'info' for 'info' variant.

  • auto_close (bool | int) –

    Auto-close duration in milliseconds. Set to False to keep the notification open until the user closes it manually. Default value depends on variant: 4000 for info/success/warning/error, False for progress.

Example

```python import vizro.actions as va import vizro.models as vm

vm.Button( text="Save", actions=[ va.show_notification(id="save_notification", text="Saving data...", variant="progress"), va.export_data(), va.update_notification( notification="save_notification", text="Data saved successfully!", variant="success" ), ], )

```