Maybe I’m missing something fundamental, but I simply don’t know an answer. Therefore it would be very kind if someone could help me out:
I’m trying to adapt a feature provided by @adamschroeder on his YouTube-Channel : https://www.youtube.com/watch?v=NuoA08b-cMM
In his example the confirm-dialog pops up if no variables are selected by the Multi-Value Dropdown. I like this idea and would like to use it for my own app and Default Dropdowns.
The simplified Multi-Value Dropdown code looks like this:
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.ConfirmDialog(
id='confirm-dialog',
displayed=False,
message='Please choose Dropdown variables!',
),
dcc.Dropdown(
id='demo-dropdown',
options=[
{'label': 'New York City', 'value': 'NYC'},
{'label': 'Montréal', 'value': 'MTL'},
{'label': 'San Francisco', 'value': 'SF'}
],
multi=True,
value="MTL"
),
html.Div(id='dd-output-container')
])
@app.callback(
Output('confirm-dialog','displayed'),
Output('dd-output-container', 'children'),
[Input('demo-dropdown', 'value')])
def update_output(value):
if len(value) > 0:
return False, 'You have selected "{}"'.format(value)
if len(value)==0:
return True, dash.no_update
if __name__ == '__main__':
app.run_server(debug=False)
BUT if I apply the same idea on a Default Dropdown:
dcc.Dropdown(
id='demo-dropdown',
options=[
{'label': 'New York City', 'value': 'NYC'},
{'label': 'Montréal', 'value': 'MTL'},
{'label': 'San Francisco', 'value': 'SF'}
],
# multi=True,
value="MTL"
),
I only get this error:
TypeError: object of type ‘NoneType’ has no len()
And the cofirm-dialog doesn’t pop up if no variable is selected…
Does someone understand why ‘value’ is ‘None’ is this case?
Thanks a lot!