ExtendData with traces of different types

I am streaming live candlestick data:

@app.callback(Output('graph', 'extendData'), [Input('interval', 'n_intervals')], 
[State("graph", "figure")])
def update_data(n_intervals, existing):
        
        # work directly with existing['data'][0] and determine 
        # if you need to append to it or modify its [-1] entry here

        return [
                {
                    "x": [existing["data"][0]["x"]],
                    "open": [existing["data"][0]["open"]],
                    "high": [existing["data"][0]["high"] ],
                    "low": [existing["data"][0]["low"]],
                    "close": [existing["data"][0]["close"]]
                },
                [0],
                len(existing["data"][0]["open"]) 
            ]

How would I go about extending a second trace for a Scatter plot?

As the Scatter trace only has ‘x’ and a ‘y’ elements and the main Candlestick trace does not have a ‘y’ and has a bunch of candlestick elements that the Scatter lacks, how would I go about extending both traces?

Have tried sending empy lists for the missing atributes but that does not work

1 Like

I don’t think this is currently supported. The extendData uses Plotly.extendTraces from the js library and it checks internally if each trace being update has all the keys in the update object. This is where it is done, in case you are wondering.

I tried adding another callback function with the only purpose of updating the second trace but that does not seem to work…

Is it not allowed to have 2 functions tha do "extendData’?

Not by default, but you can try to use MultiplexerTransform from dash-extensions.

Has this issue been solved in more recent versions? I think it’s really useful to have.
I’m facing the same issue trying to update candlestick trace and volume bars at the same time… !

Hi @hassan, @sfvasfdvsdfvdsv
Take a look at this fork of the plotly Graph component, it has a better extendData function that allow to generate new traces and mix multiple trace type. It also add a prependData function to the graph.

https://github.com/bcliang/dash-extendable-graph

I’m using it for my project and had good result so far but I haven’t tried to extend different trace type yet.

1 Like

Thank you so much! @Eledwin
It works perfectly. I’m glad I asked here.
One limitation is marker color cannot be updated. That’s unfortunate…