Dcc.dropdown - can we force a minimum of 1 option to be selected

I have added a dcc.Dropdown to choose or or multiple of the weekdays. I notice that deselecting all will cause a pop-up error because there are then no matches in the dataframe used.

Can we force the user to never deselect all? Alternative I could do something like write a custom function that will check if the dataframe is empty and in that case return something else. But this seems like a lot of work and in that case, I would probably prefer just using something like the ipywidgets.SelectMultiple where it’s simply not possible to deselect all.

I don’t think you can force this. You could catch that case at the start of your callback: If no option has been chosen, choose one programmatically, i.e.

Could you prevent the callback in this case or are there other things happening which you still want to be executed in the callback?

That makes sense, I’ll try doing that.
But upon a further look, it turns out that the problems occurs when the dataframe has no content, not specifically for the weekday dropdown, but when any slider value causes this.

So maybe I should start by adding a check at the beginning of the callback function to handle cases with an empty dataframe - somehow avoid running the usual outputs.

Currently seeing this error:

Traceback (most recent call last):
  File "C:\Users\Simon\AppData\Local\Programs\Python\Python311\Lib\site-packages\plotly\express\_chart_types.py", line 66, in scatter
    return make_figure(args=locals(), constructor=go.Scatter)
  File "C:\Users\Simon\AppData\Local\Programs\Python\Python311\Lib\site-packages\plotly\express\_core.py", line 1933, in make_figure
    args = build_dataframe(args, constructor)
  File "C:\Users\Simon\AppData\Local\Programs\Python\Python311\Lib\site-packages\plotly\express\_core.py", line 1324, in build_dataframe
    raise ValueError(
ValueError: Cannot accept list of column references or list of columns for both `x` and `y`.

Preventing deselection of all weekdays in dcc.Dropdown could be tricky, Using ipywidgets.SelectMultiple might be a simpler solution if it aligns better with your needs. Less work, more convenience!

I think it’ll be pretty difficult to help you any further without knowing more in detail what you are trying to do.