In a Shiny for Python app, I have a go.Scattermap wrapped in a go.FigureWidget, and with a function on_map_select() registered as callback to mapwidget.data[0]. There is only one trace in the figure.
The callback is being called OK for single point selections as well as box selections.
However, for lasso selections the callback is not invoked. No crash or error.
In the Shiny UI, both box and lasso selections appear to behave similarly, highlighting the markers within the selected area.
Bug or missing feature? Anyone experienced something similar?
Plotly 6.2.0, Python 3.12, Shiny 1.2.1, Windows 11.
Plotly 6.1.1 and ScatterMapBox also tried, same behaviour.
The map has around 140 markers (have seen posts where this number was relevant).
New update: It appears that the lasso selector works OK, and that the error is that str(selector) fails when selector is a plotly.callbacks.LassoSelector’. Within the Shiny framework, that error caused the callback to abort silently.
To reproduce the error (plotly 6.3.1):
(venv) PS C:\Devel\PyProj\PlotlyLassoTest> python
Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
Ctrl click to launch VS Code Native REPL
lasso_selector = callbacks.LassoSelector()
type(lasso_selector)
<class ‘plotly.callbacks.LassoSelector’>
lasso_selector
Traceback (most recent call last):
File “”, line 1, in
File “c:\Users\sak\AppData\Roaming\Code\User\workspaceStorage\483d815d6720e46e72b3e1eba8bd7f7e\ms-python.python\pythonrc.py”, line 24, in my_displayhook
self.original_displayhook(value)
File “C:\Devel\PyProj\PlotlyLassoTest\venv\Lib\site-packages\plotly\callbacks.py”, line 257, in repr
xs=_list_repr_elided(self.xs, indent=len(“LassoSelector(xs=”)),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Devel\PyProj\PlotlyLassoTest\venv\Lib\site-packages\plotly\utils.py”, line 30, in _list_repr_elided
raise ValueError(“Invalid value of type: %s” % type(v))
ValueError: Invalid value of type: <class ‘NoneType’>
So, in the minimal working example in comment #1 above, it is the “selector is {selector}” in the last diagnostic print that causes on_map_select() to abort silently if the selector is a LassoSelector. It works as expected for a BoxSelector, or if selector is None, as it is for a single-click selection. The special case of Lasso when selecting only a single point was an artefact of not trying to print the selector when len(points.point_inds) == 1.