Axel Puig
Axel Puig

Reputation: 1334

Plotly-Dash: How to update only figure data without changing the figure layout?

I have a 3D scatter plot, I want to update the data of the figure (when moving a slider) without changing the 3D view.

Even with this solution, the 3D view is reset:

@app.callback(Output('graph', 'figure'),
              Input('slider', 'value'),
              State('graph', 'figure'))
def update_fig(value, figure):
    if value is not None:
        data = new_data(value)
        figure['data'][0]['x'] = data['x']
        figure['data'][0]['y'] = data['y']
        figure['data'][0]['z'] = data['z']
        return figure
    else:
        return figure

Is it possible to update only the coordinates of the points?

Upvotes: 5

Views: 3326

Answers (1)

vestland
vestland

Reputation: 61084

The following should do what you want:

fig.update_layout(uirevision='constant')

If it doesn't, then please consider providing a snippet with a sample of your data and a fully runnable dash setup. I'm sure we can figure it out somehow.

Upvotes: 6

Related Questions