Button On Click Not Responding After Selection

I have the following code that creates a simple cross selector and pressing the button should print out what was selected:

button = pn.widgets.Button(name='Update', button_type='primary')
cross_selector = pn.widgets.CrossSelector(name='Fruits', options=['Apples', 'Bananas', 'Cranberries'])

def update_all(event):
    print(cross_selector.value)
    # Eventually update some plot with df[cross_selector.value]

button.on_click(update_all)

pn.Column(cross_selector, button)

Initially, when nothing is selected, pressing the button prints out an empy list. However, once something is selected and moved over to the right, pressing the button does not print anything anymore and I can’t seem to figure out why.

Hi @seanlaw,

I’ve been able to reproduce what you observed. It’s a little strange as if you check your browser console you should actually observe that the right value is being logged. However, it seems that in the notebook the log stops being emitted as soon as you interact with the CrossSelector.

Do you mind creating a bug report?

Github Bug Report

@maximlt Are you aware of any other alternatives for sub-selecting from a list that is similar to the cross selector? Ultimately, the selection will be used to query/filter a Pandas dataframe and then update a plot dynamically.

Either pn.widgets.MultiSelect or pn.widgets.MultiChoice should do the trick.

Maybe also try to take a look at what hvplot.interactive can do: interactive — hvPlot 0.8.2 documentation

Thanks @Hoxbro. In my real use case, I have something like 4000+ items in the list and so the Cross Selector was nice because you can narrow things down by typing in keywords in order to filter down the list. :frowning_face:

Ahh. I see.

I suspect the function is called and run but not showing the output for some reason.

You are running the code in a notebook, correct? Can you try to recreate it in a python file with .servable?

If you want to be sure the cell is run in a notebook, you could try to replace the print statement with a ValueError or similar.

Yes, I am running with a notebook but I’m seeing the same behavior with panel serve and .servable

In my testing the selection in the cross selector had no problem, the issue was the logs emitted by the print statement not being displayed in the Notebook (but being correctly displayed in the console). So I think the functionality you’re looking for is working.

Are you looking for another widget to try to improve the UX?

1 Like

@maximlt You’re right! Thank you

1 Like