Skip to content

[BUG] dcc.Graph figure prop may include Plotly.js _inputArray for typed arrays #3847

Description

@AnnMarieW

When a dcc.Graph figure data contains typed arrays (for example int8, float32, etc.), the figure can include a Plotly.js internal field _inputArray

In the example below, the _inputArray is included after user interaction but not when the figure is first rendered.

_inputArray duplicates bdata and also includes decoded data, increasing callback payload size and overhead for large datasets.

Possible fixs:

  • strip _inputArray in dcc.Graph before updating the figure prop. But that might be considered a breaking change since some people are now using _inputArray in callbacks.
  • Have an option to not encode np arrays when using dash. This will also fix the issue of customdata not being available is clickData, hoverData if they are np arrays

Other related issues:


When app first renders (no _inputArray):

Image

After hover (with _inputArray):

Image

Sample App:

from dash import Dash, html, dcc, Input, Output
import numpy as np
import plotly.express as px
import json

app = Dash()

data = np.random.normal(0, 1, 250)
fig = px.histogram(data, nbins=20)

app.layout = html.Div([
    dcc.Graph(id="graph", figure=fig),
    html.Pre(id="fig-data")
])


@app.callback(
    Output("fig-data", "children"),
    Input("graph", "figure"),
    Input("graph", "hoverData"),
)
def debug(figure, hoverData):
    return json.dumps(figure["data"][0]["x"], indent=4)


if __name__ == "__main__":
    app.run(debug=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions