Black Lives Matter. Please consider donating to Black Girls Code today.

Retain pan/zoom across live updates

Greetings,

I would like to implement live streaming with Plotly & Dash (although I am not particularly attached to the latter) such that the view is not reset when the data is updated. My data is not time-series; a new data frame is loaded on each update. The dynamic range is known statically.

I followed these guides (aside from the main docs):

This is the relevant fragment of my MWE:

@app.callback(dash.dependencies.Output('graph-3d', 'figure'),
              [dash.dependencies.Input('interval-component', 'n_intervals')])
def on_timer_3d(n_intervals):
    n_points = 1000
    x = numpy.random.randn(n_points) + 5
    y = numpy.random.randn(n_points) + 5
    z = numpy.random.randn(n_points) + 5
    w = numpy.random.randn(n_points)

    trace = dict(
        type='scatter3d',
        x=x,
        y=y,
        z=z,
        mode='markers',
        marker=dict(
            line_width=0,
            size=1,
            color=w,
            colorscale='Jet',
            showscale=True,
        ),
    )

    axis_layout = dict(
        range=(0, 10),
        backgroundcolor='#000',
        showbackground=True,
        gridcolor='#555',
        zerolinecolor='#888',
    )

    layout = go.Layout(
        width=700,
        height=700,
        scene_aspectmode='cube',
        scene=dict(
            xaxis=axis_layout,
            yaxis=axis_layout,
            zaxis=axis_layout,
        ),
        paper_bgcolor=BACKGROUND_COLOR,
        font=dict(
            color=FOREGROUND_COLOR,
        ),
    )

    return dict(data=[trace], layout=layout)

This is what it looks like (for reference):

I would like the configuration of the view (such as zoom and orientation) to remain invariant to live updates. How do I do that? I searched the docs thoroughly but couldn’t find any coverage of this issue aside from the above two articles.

search for “uirevision” in the forum, i don’t think it’s officially documented yet

Thank you! It does just what I need. For the benefit of posterity, here is the whole diff:

         font=dict(
             color=FOREGROUND_COLOR,
         ),
+        # https://community.plotly.com/t/preserving-ui-state-like-zoom-in-dcc-graph-with-uirevision/15793
+        uirevision='0',
     )
 
     return dict(data=[trace], layout=layout)