plotly / plotly/dash

Using relayoutData as input causes callback to be triggered on initial load even if prevent_initial_call=True

Open
#2,668 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

Bug description
Hello there, I am working on a dash app in which user changes to the relayoutData of a visual e.g. changing the zoom level should trigger a callback function and I want this callback to not be run on initial_load. However, it seems that using relayoutData as an input for my callback function results in the callback being triggered on initial load regardless of whether I set prevent_initial_call=True or False. I have implemented a fix for this issue myself by using the following conditional check at the start of the callback function:

if not ctx.triggered_id:
       raise PreventUpdate

Here is the callback definition:

@dash_app.app.callback(
    Output("fig_drydown", "figure", allow_duplicate=True),
    Output("fig_shot_size", "figure", allow_duplicate=True),
    Output("fig_drain_percentage", "figure", allow_duplicate=True),
    Output("fig_ec_info", "figure", allow_duplicate=True),
    Output("fig_irrigation_strategy", "figure", allow_duplicate=True),
    Input("fig_drydown", "relayoutData"),
    Input("fig_shot_size", "relayoutData"),
    Input("fig_drain_percentage", "relayoutData"),
    Input("fig_ec_info", "relayoutData"),
    Input("fig_irrigation_strategy", "relayoutData"),
    State("fig_drydown", "figure"),
    State("fig_shot_size", "figure"),
    State("fig_drain_percentage", "figure"),
    State("fig_ec_info", "figure"),
    State("fig_irrigation_strategy", "figure"),
    State("cultivation_x_axis_range", "data"),
    prevent_initial_call=True,
)
def adjust_visual_zoom(
    fig_drydown_relayout: go.Figure,
    fig_shot_size_relayout: go.Figure,
    fig_drain_percentage_relayout: go.Figure,
    fig_ec_info_relayout: go.Figure,
    fig_irrigation_strategy_relayout: go.Figure,
    fig_drydown: go.Figure,
    fig_shot_size: go.Figure,
    fig_drain_percentage: go.Figure,
    fig_ec_info: go.Figure,
    fig_irrigation_strategy: go.Figure,
    initial_x_axis_range: dict,
):

Context
Please provide us your environment, so we can easily reproduce the issue.

  • replace the result of pip list | grep dash below
dash                 "2.14.0"
dash-core-components "2.0.0"
dash-html-components "2.0.0"
dash-table           "5.0.0"
``

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied Dash callback with relayoutData inputs and prevent_initial_call=True, using the reported Dash 2.14.0 environment. Trace how the initial relayoutData value reaches the callback and how prevent_initial_call is applied. Done when initial loading does not invoke the callback, while user zoom or layout changes still do.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.