@@ -159,20 +159,24 @@ def _update_figure(self):
159159 if (fig is None or isinstance (fig , (dict , list , tuple )) or fig is self ._figure or not self .link_figure ):
160160 return
161161
162- # Monkey patch the message stubs used by FigureWidget.
163- if not hasattr (fig , '_send_addTraces_msg' ):
162+ def _from_plotly (attr ):
163+ mod_attr = getattr (fig , attr , None )
164+ return mod_attr is None or getattr (mod_attr , "__module__" , "" ).startswith ('plotly' )
165+
166+ # Monkey patch the message stubs used by FigureWidget, only if the method is from plotly
167+ if _from_plotly ('_send_addTraces_msg' ):
164168 fig ._send_addTraces_msg = lambda * _ , ** __ : self ._update_from_figure ('add' )
165- if not hasattr ( fig , '_send_deleteTraces_msg' ):
169+ if _from_plotly ( '_send_deleteTraces_msg' ):
166170 fig ._send_deleteTraces_msg = lambda * _ , ** __ : self ._update_from_figure ('delete' )
167- if not hasattr ( fig , '_send_moveTraces_msg' ):
171+ if _from_plotly ( '_send_moveTraces_msg' ):
168172 fig ._send_moveTraces_msg = lambda * _ , ** __ : self ._update_from_figure ('move' )
169- if not hasattr ( fig , '_send_restyle_msg' ):
173+ if _from_plotly ( '_send_restyle_msg' ):
170174 fig ._send_restyle_msg = self ._send_restyle_msg
171- if not hasattr ( fig , '_send_relayout_msg' ):
175+ if _from_plotly ( '_send_relayout_msg' ):
172176 fig ._send_relayout_msg = self ._send_relayout_msg
173- if not hasattr ( fig , '_send_update_msg' ):
177+ if _from_plotly ( '_send_update_msg' ):
174178 fig ._send_update_msg = self ._send_update_msg
175- if not hasattr ( fig , '_send_animate_msg' ):
179+ if _from_plotly ( '_send_animate_msg' ):
176180 fig ._send_animate_msg = lambda * _ , ** __ : self ._update_from_figure ('animate' )
177181 self ._figure = fig
178182
0 commit comments