Skip to content
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

[BUG] Graph Viewpoint Reset Issue #2281

Open
vbanerje opened this issue Oct 24, 2022 · 0 comments
Open

[BUG] Graph Viewpoint Reset Issue #2281

vbanerje opened this issue Oct 24, 2022 · 0 comments
Labels

Comments

@vbanerje
Copy link

I want to modify the contents of a 3d scatterplot (from plotly.graph_objects) based on keyboard input in a Dash application. Since the 3d scatterplot is interactable, the user is able to change the viewpoint and pan the camera to explore the scatterplot.

When keyboard input is received, the scatterplot is returned but the camera position and rotation does not persist. However, it does persist if the user gives two or more consecutive keyboard inputs.

These are the steps to recreate the issue. If I rotate and/or pan the camera and press "r", then rotate and/or pan the camera again and press "r", the camera suddenly snaps to the last position instead of maintaining the current position.
However, if rotate and/or pan the camera and press "r" twice, then rotate and/or pan the camera and press "r" twice, the camera no longer snaps to the last position and maintains the current position.

Please let me know if I am missing a parameter or argument when creating the dcc.Graph object to stop this snapping behavior.
Here is the code to reproduce the issue

import numpy as np
import plotly.graph_objects as go
from dash_extensions import Keyboard
from dash import Dash, dcc, html, Input, Output, no_update

def create_app():
    app = Dash(__name__)
    data = np.random.rand(1000,3)
    fig = go.Figure(go.Scatter3d(
            x=data[:,0],
            y=data[:,1],
            z=data[:,2],
            mode='markers',
            ))
    fig.update_traces(hoverinfo="none", hovertemplate=None)
    fig.update_layout(
        autosize=False,
        width=900,
        height=600,
        uirevision='constant',
        margin= {'b':0,'l':0,'r':0,'t':0,'pad':0},
        xaxis = {'visible': False, 'showticklabels': False},
        yaxis = {'visible': False, 'showticklabels': False},
        scene = dict(
            aspectmode='cube',
            camera = dict(center=dict(x=0,y=0,z=0), eye=dict(x=1.25,y=1.25,z=1.25),up=dict(x=0,y=0,z=1))
            ))

    app.layout = html.Div(
        [
            dcc.Graph(
                id="scatter-graph",
                figure=fig,
                clear_on_unhover=True,
            ),
            Keyboard(id='keyboard')
        ]
    )

    @app.callback(
        Output('scatter-graph', 'figure'),
        Input('scatter-graph', 'figure'),
        Input('keyboard', 'keydown'),
        Input('keyboard', 'n_keydowns'),
    )
    def foo(graph_fig, keydown, keypress):
        if keydown and keydown['key'].lower() == 'r':
            print('return graph')
            '''
            Some operations to modify the contents of the graph.
            '''
            return graph_fig
        print('no update')
        return no_update

    return app

if __name__ == '__main__':
    app = create_app()
    app.run_server(debug=True, use_reloader=False)

Libraries:

- dash==2.6.2
- dash-core-components==2.0.0
- dash-extensions==0.0.29rc2
- dash-html-components==2.0.0
- numpy==1.23.3
- plotly==5.10.0
@vbanerje vbanerje changed the title Graph Viewpoint Reset Issue [BUG] Graph Viewpoint Reset Issue Oct 24, 2022
@T4rk1n T4rk1n added the Graph label Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants