Plolty throwing error when run multiple time on the same FigureWidget

So I have attached a figurewidget to a tab and plotting data based on a dropdown selection. The flow is → I select an item from dropdown → click “plot” and it erases the previous traces and plots the new trace". The error that I am facing is that sometimes the change event is caught by _handler_js2py_pointsCallback method when I change the dropdown selection. This occurs randomly (sometimes after 4 selections, sometime it occurs after 20 times). Can we have the name checked when the change dictionary is processed inside _handler_js2py_pointsCallback method, such that it only handles change[‘name’] == ‘_js2py_pointsCallback’ (I’m assuming that all change dictionary pertaining to FigureWidget has this name)

The following is the stack trace that I get:
KeyError Traceback (most recent call last)
/gpfs/apps/team_name/stacks/3/condaenv/kernel/1.0/conda/lib/python3.7/site-packages/ipywidgets/widgets/ in _handle_msg(self, msg)
674 if ‘buffer_paths’ in data:
675 _put_buffers(state, data[‘buffer_paths’], msg[‘buffers’])
→ 676 self.set_state(state)
678 # Handle a state request.

/gpfs/apps/team_name/stacks/3/condaenv/kernel/1.0/conda/lib/python3.7/site-packages/ipywidgets/widgets/ in set_state(self, sync_data)
543 from_json = self.trait_metadata(name, ‘from_json’,
544 self._trait_from_json)
→ 545 self.set_trait(name, from_json(sync_data[name], self))
547 def send(self, content, buffers=None):

/gpfs/apps/team_name/stacks/3/condaenv/kernel/1.0/conda/lib/python3.7/ in exit(self, type, value, traceback)
117 if type is None:
118 try:
→ 119 next(self.gen)
120 except StopIteration:
121 return False

/gpfs/apps/team_name/stacks/3/condaenv/kernel/1.0/conda/lib/python3.7/site-packages/traitlets/ in hold_trait_notifications(self)
1212 for changes in cache.values():
1213 for change in changes:
→ 1214 self.notify_change(change)
1216 def _notify_trait(self, name, old_value, new_value):

/gpfs/apps/team_name/stacks/3/condaenv/kernel/1.0/conda/lib/python3.7/site-packages/ipywidgets/widgets/ in notify_change(self, change)
604 # Send new state to front-end
605 self.send_state(key=name)
→ 606 super(Widget, self).notify_change(change)
608 def repr(self):

/gpfs/apps/team_name/stacks/3/condaenv/kernel/1.0/conda/lib/python3.7/site-packages/traitlets/ in notify_change(self, change)
1225 def notify_change(self, change):
1226 “”“Notify observers of a change event”""
→ 1227 return self._notify_observers(change)
1229 def _notify_observers(self, event):

/gpfs/apps/team_name/stacks/3/condaenv/kernel/1.0/conda/lib/python3.7/site-packages/traitlets/ in _notify_observers(self, event)
1262 c = getattr(self,
→ 1264 c(event)
1266 def _add_notifiers(self, handler, name, type):

/gpfs/apps/team_name/stacks/3/condaenv/kernel/1.0/conda/lib/python3.7/site-packages/plotly/ in _handler_js2py_pointsCallback(self, change)
708 ):
→ 710 trace_dict = trace_points[trace_ind]
711 trace_dict[“xs”].append(x)
712 trace_dict[“ys”].append(y)

KeyError: 1

Can anybody help me with this?

So I see that there is a decorator which observes if this change is of name ‘_js2py_pointsCallback’, but then why does it get invoked? Is this problem with plotly figurewidget or with ipywidgets