Skip to content

uirevision property doesn't keep the viewpoint consistent #3951

Open
@lpuglia

Description

@lpuglia

The following is the copy-paste of a question I opened on stackoverflow, it looks like to be a bug, so here i go:

I'm trying to keep the viewpoint consistent in my plotly-dash web app after every callback. This should be straightforward according to many already answered questions. The following line of code should do the magic:

fig.update_layout(uirevision='constant')

Unfortunately for me, it looks like that this is not the case for 3D scatter plots, here is a very brief piece of code that should allow to reproduce my problem:

import plotly.express as px
df = px.data.iris()

import dash
from dash import dcc
from dash import html
from dash import Input, Output

app = dash.Dash()
app.layout = html.Div([
    dcc.Dropdown(['option1', 'option2', 'option3'], 'axis', id='x-dropdown', clearable=False),
    dcc.Graph(id='main-plot')
])
@app.callback(
    Output('main-plot', 'figure'),
    Input('x-dropdown', 'value'))
def update_figure(x_selector):
    fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',  color='species')
    fig.update_layout(uirevision='constant')
    return fig
    
app.run_server(debug=True, use_reloader=False)

This is what i'm observing:
unexpected behavior

I can tell that the uirevision is doing something since the viewpoint is not completely reset after the callback, but it is still very imprecise. Is there something I'm missing or is this the expected behavior?

Activity

dmalinverni

dmalinverni commented on Jul 24, 2023

@dmalinverni

Following up on @lpuglia's question, as I'm facing the same problem.
I've tried several combinations of uirevsion in layout and in scene, but with no success.

Are there any updates on this issue?
Thanks

jackhhchan

jackhhchan commented on Sep 30, 2023

@jackhhchan

Any update on this issue? I'm also experiencing the same thing

plotly 5.17.0

DoctorDinosaur

DoctorDinosaur commented on Nov 20, 2023

@DoctorDinosaur

Same issue for me, 3d scatter plot seems to ignore uirevision.

I'm instead having to store the state of the camera.

lpuglia

lpuglia commented on Nov 20, 2023

@lpuglia
Author

@DoctorDinosaur can you share a workaround?

DoctorDinosaur

DoctorDinosaur commented on Nov 20, 2023

@DoctorDinosaur
app = Dash(__name__)
app.layout = html.Div(
    [
        # ... Your dash elements
        dcc.Store(id="camera"),
    ]
)

# Callback to store camera position
@app.callback(
    dd.Output("camera", "data"),
    dd.Input("graph", "relayoutData"),
)
def store_camera_position(relayoutData):
    if relayoutData is not None:
        if "scene.camera" in relayoutData:
            return relayoutData["scene.camera"]
    return no_update
    
# ... some code ....


@app.callback(
    dd.Output("graph", "figure"),
    # ... Your other callback stuff
    dd.State("graph", "figure"),
    dd.State("camera", "data"),
)
def your_callback_func(... , figure, camera):
    if camera is not None:
        figure["layout"]["scene"]["camera"] = camera
    # ... The rest of your callback func
    return figure

Little buggy, but better than nothing. I'm sure someone with more experience can refine this.

added
bugsomething broken
sev-3annoyance with workaround
P3backlog
and removed on Nov 21, 2023
mohsenminaei

mohsenminaei commented on Dec 11, 2023

@mohsenminaei

I have an observation that might be useful to whoever that's going to fix this problem.

I have a graph object Scatter3d plot. uirevision works fine when I update the plot data. But it breaks down when I maximize the browser tab (in general, change tab size). From that point on, the camera resets each time there is an update to the plot.

self-assigned this
on Jul 11, 2024
removed their assignment
on Aug 2, 2024

2 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething brokensev-3annoyance with workaround

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      uirevision property doesn't keep the viewpoint consistent · Issue #3951 · plotly/plotly.py