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

Can't output to extendData without any data

I have a graph that I’m trying to update realtime as new data comes in. I’ve got a callback going from an Interval to extendData on the graph. However, sometimes I don’t have any new data yet when the interval fires. Whenever this happens the console on the browser shows a “indices must be valid indices for gd.data” error.

I’ve tried multiple variations of return value, but they all throw this error, even though the plotly extendTraces method works fine with several variations of empty data (you can play around with this codepen to prove it).

I’ve tried returning:

  • None
  • [ ]
  • [{}]
  • [{‘x’:[ ],‘y’:[ ]}]
  • [{‘x’:[[ ]],‘y’:[[ ]]}]

(I return [{‘x’:[[value]],‘y’:[[value]]}] when I have data to return, which works fine)

Anyone have any idea what I’m doing wrong here?