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.

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: 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: 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: triggers set_control when user clicks on the figure. value specifies a literal value to set control to.

  • Button: triggers set_control when user clicks on the button. value specifies a literal value to set control to.
  • 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"),
)