Skip to content

uirevision property doesn't keep the viewpoint consistent #3951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lpuglia opened this issue Nov 12, 2022 · 7 comments
Open

uirevision property doesn't keep the viewpoint consistent #3951

lpuglia opened this issue Nov 12, 2022 · 7 comments
Labels
bug something broken P3 backlog sev-3 annoyance with workaround

Comments

@lpuglia
Copy link

lpuglia commented Nov 12, 2022

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?

@dmalinverni
Copy link

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
Copy link

jackhhchan commented Sep 30, 2023

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

plotly 5.17.0

@DoctorDinosaur
Copy link

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

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

@lpuglia
Copy link
Author

lpuglia commented Nov 20, 2023

@DoctorDinosaur can you share a workaround?

@DoctorDinosaur
Copy link

DoctorDinosaur commented Nov 20, 2023

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.

@Coding-with-Adam Coding-with-Adam added bug something broken sev-3 annoyance with workaround p4 P3 backlog and removed p4 labels Nov 21, 2023
@mohsenminaei
Copy link

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.

@ntellis
Copy link

ntellis commented May 12, 2025

I'm experiencing this issue as well.

DoctorDinosaur's workaround looks good, but in my application we server-generate our plots out as html and then render them. Haven't been able to get a similar camera sleight of hand working yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog sev-3 annoyance with workaround
Projects
None yet
Development

No branches or pull requests

8 participants