Skip to content

UI revision does not work while specifying projection type #6840

@EdosOs

Description

@EdosOs

i’ve been unable to make uirevision to work while using the orthographic projection on 3D scatter plot using graph object.
here’s a simplified example (i'm not as familiar with JS , therefore the example is in python.) :

import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import pandas as pd
from numpy.random import randn
# Sample data
data = {
    'sepal_width': [3.5, 3.0, 3.2, 3.1, 3.6],
    'sepal_length': [5.1, 4.9, 4.7, 4.6, 5.0],
    'petal_length': [1.4, 1.4, 1.3, 1.5, 1.4],
}
data2 = {
    'sepal_width': [3.5, 3.0, 3.2, 3.1, 3.6]*3,
    'sepal_length': [5.1, 4.9, 4.7, 4.6, 5.0]*2,
    'petal_length': [1.4, 1.4, 1.3, 1.5, 1.4]*1,
}
df = pd.DataFrame(data)

# Initial Figure
scatter_figure = go.Figure()
scatter_figure.layout.uirevision = True
scatter_figure.layout.scene.camera.projection.type = 'orthographic'
# Add 3D Scatter Plot Trace
scatter_figure.add_trace(
    go.Scatter3d(
        x=df['sepal_width'],
        y=df['sepal_length'],
        z=df['petal_length'],
        mode='markers',
        marker=dict(
            size=12,
            opacity=0.7,
        ),
        scene='scene',
    )
)

# Dash app
app = dash.Dash(__name__)

# Layout
app.layout = html.Div([
    dcc.Graph(
        id='scatter-plot',
        figure=scatter_figure,
    ),
    dcc.Checklist(
        id='toggle-checklist',
        options=[
            {'label': 'Toggle Plot', 'value': 'toggle'}
        ],
        value=['toggle'],
    ),
])

# Callback to toggle plot visibility
@app.callback(
    Output('scatter-plot', 'figure'),
    [Input('toggle-checklist', 'value')]
)
def toggle_plot(value):
    if 'toggle' in value:
        # If 'toggle' is in the value, show the plot
        return scatter_figure
    else:
        df = data2
        scatter_figure.add_trace(
            go.Scatter3d(
                x=df['sepal_width'],
                y=df['sepal_length'],
                z=df['petal_length'],
                mode='markers',
                marker=dict(
                    size=12,
                    opacity=0.7,
                ),
                scene='scene',
            )
        )
        return scatter_figure

# Run the app
if __name__ == '__main__':
    app.run_server(debug=True,port = 8078)

every time I'm toggling the check box the view completely reversed to its original position, and only when I'm specifying projection to be orthographic , works perfectly on perspective.

I'd really appeiciate you looking into this :)
Happy New Year and thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclebugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions