Skip to content

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

Open

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)

Activity

  1. changed the title [-][BUG] `dcc.Graph` callback payload may include Plotly.js `_inputArray` for typed arrays[/-] [+][BUG] `dcc.Graph` `figure` prop may include Plotly.js `_inputArray` for typed arrays[/+] on Jun 26, 2026
  2. AnnMarieW commented on Jun 26, 2026

    @AnnMarieW
    Author

    Here's a proposal for a function to decode a typed array in a dash callback:

    import base64
    import numpy as np
    
    SHORT_TO_NUMPY = {
        "i1": np.int8,
        "u1": np.uint8,
        "i2": np.int16,
        "u2": np.uint16,
        "i4": np.int32,
        "u4": np.uint32,
        "f4": np.float32,
        "f8": np.float64,
    }
    
    
    def decode_typed_arrays(obj):
        if isinstance(obj, dict):
    
            if (
                "dtype" in obj
                and "bdata" in obj
                and obj["dtype"] in SHORT_TO_NUMPY
            ):
                try:
                    arr = np.frombuffer(
                        base64.b64decode(obj["bdata"]),
                        dtype=SHORT_TO_NUMPY[obj["dtype"]],
                    )
    
                    if "shape" in obj:
                        shape = tuple(
                            int(x.strip())
                            for x in str(obj["shape"]).split(",")
                            if x.strip()
                        )
                        arr = arr.reshape(shape)
    
                    return arr.tolist()
    
                except Exception:
                    return obj
    
            return {
                k: decode_typed_arrays(v)
                for k, v in obj.items()
                if k != "_inputArray"
            }
    
        if isinstance(obj, list):
            return [decode_typed_arrays(v) for v in obj]
    
        return obj
  3. robertclaus commented on Jul 23, 2026

    @robertclaus

    Thank you for the write-up @AnnMarieW . We'll likely need to fix this in plotly.py.

  4. AnnMarieW commented on Jul 23, 2026

    @AnnMarieW
    Author

    @robertclaus
    That makes sense. Would you like me to close this here?

  5. transferred this issue fromplotly/dashon Jul 27, 2026
  6. camdecoster commented on Jul 30, 2026

    @camdecoster
    Contributor

    @AnnMarieW we transferred the issue over, so no need to close it.

  7. emilykl commented on Sep 2, 2026

    @emilykl
    Contributor

    Related: #5124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclebugsomething brokensize: 3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions