Handler passed to on_selection() not getting triggered


Thank you for the great library.

I have been following the tutorials namely: https://plot.ly/python/selection-events/. The selection from the drop-down menus work file. However, the selection with the mouse on the canvas as shown in the animated gif shown on that URL does nothing on my computer. I have tested on Firefox 73.0.1 as well as on Chromium 80.0.3987.122 and same issue. I looked at the console (developer tools when the selection is happening and no errors). I have a new virtual virtual environment with just the following packages installed: jupyter, plotly. Here is a complete list of all the packages that got subsequently installed as a consequence of installing the latter ones:

Package            Version
------------------ -------
attrs              19.3.0 
backcall           0.1.0  
bleach             3.1.1  
decorator          4.4.2  
defusedxml         0.6.0  
entrypoints        0.3    
importlib-metadata 1.5.0  
ipykernel          5.1.4  
ipython            7.13.0 
ipython-genutils   0.2.0  
ipywidgets         7.5.1  
jedi               0.16.0 
Jinja2             2.11.1 
jsonschema         3.2.0  
jupyter            1.0.0  
jupyter-client     6.0.0  
jupyter-console    6.1.0  
jupyter-core       4.6.3  
MarkupSafe         1.1.1  
mistune            0.8.4  
nbconvert          5.6.1  
nbformat           5.0.4  
notebook           6.0.3  
pandocfilters      1.4.2  
parso              0.6.2  
pexpect            4.8.0  
pickleshare        0.7.5  
pip                20.0.2 
pkg-resources      0.0.0  
plotly             4.5.2  
prometheus-client  0.7.1  
prompt-toolkit     3.0.3  
ptyprocess         0.6.0  
Pygments           2.5.2  
pyrsistent         0.15.7 
python-dateutil    2.8.1  
pyzmq              19.0.0 
qtconsole          4.6.0  
retrying           1.3.3  
Send2Trash         1.5.0  
setuptools         45.2.0 
six                1.14.0 
terminado          0.8.3  
testpath           0.4.4  
tornado            6.0.3  
traitlets          4.3.3  
wcwidth            0.1.8  
webencodings       0.5.1  
wheel              0.34.2 
widgetsnbextension 3.5.1  
zipp               3.0.0  

I have also made a much simpler code snippet to test things and I can see that ‘on_click()’ does work but, not ‘on_selection()’. Here is the code:

from random import random
import plotly.graph_objs as go
import plotly.offline as py


x = [int(random() * 100) for i in range(10)]
y = [int(random() * 100) for i in range(10)]

fig = go.FigureWidget([go.Scatter(x=x, y=y, mode="markers")])
sca = fig.data[0]

def click_handler(trace, points, selector):
    print("clicked something")

def selection_handler(trace, points, selector):
    print("selected something")


And finally here is an animated gif illustrating the problem with the console also open. Can you tell me what I am doing wrong and how to go about to fix the problem?

hi @Lalo,

You have to use the ‘lasso select’ or ‘box select’ in the plot toolbar in order to select data. From your Gif I can tell that you are only zooming in. :wink: