DASH MultiTab Callback Problems

Viewed 42

I am working on a multi-tab dashboard with DASH and I have some callback problems.

1. Problem: Button enabled / disbaled in connection with a checkbox: On my first tab there is a button that leads to the next tab and that should only be enabled if a checkbox is clicked. This is working. But if I unclick the checkbox, the button is still enabled even tho it should be disabled then again. Here my code:

@callback( 
    Output(component_id='start-button',component_property='disabled'), 
    Input(component_id='checklist- 
    conditions',component_property='value'),prevent_initial_call=True
)
def enable_start_button(conditions_read):
    if conditions_read == "I herby comfirm that I read...":
        disabled = False
    if conditions_read != "I herby comfirm that I read...":
        disabled = False

2. Problem: Button enabled if more pre-conditions are set: A button should be enabled only if 4 conditions are fulfilled. However, the button is already enabled if only one of the 4 conditions is fulfilled. Here the code:

@callback( 
    Output(component_id='continue1-button',component_property='disabled'), 
    Input(component_id='contact-first-name',component_property='value'),
    Input(component_id='contact-last-name',component_property='value'),
    Input(component_id='contact-mail',component_property='value'),
    Input(component_id='contact-company',component_property='value'),
    prevent_initial_call=True
)
def 
enable_start_button(first_name_checked,last_name_checked,mail_checked,company_checked):
        if first_name_checked != None and last_name_checked != None and mail_checked != 
            None and company_checked!= None:
            disabled = False

3. Problem: 2 inputs should be enabled (here dropdowns) if certain conditions are fulfilled. However, only one of the 2 inputs gets enabled, the other stays grey. For example, it should be possible to choose a new wind turbine type and rating if before the user selects in another dropdown as a turbine type = new. Here the code:

@callback( 
    Output(component_id='new-turbine',component_property='disabled'), 
    Output(component_id='new-turbine-rating',component_property='disabled'),
    Input(component_id='turbine-type',component_property='value'), 
    prevent_inital_callback = True
)
def enable_new_turbine(new_turbine):
    if new_turbine == "New":
        disabled1 = False
        disabled2 = False

I am already searching for a longer time for a solution since it seems not to be such a difficult problem. But I still have not found anything and I would be glad for any help! Thanks a lot and best regards, Lexy.

1 Answers

Edit:
The missing returns appear to be the problem.
Lets talk this through on the second Problem. By setting Output(component_id='continue1-button',component_property='disabled') you indicate that the Output of that callback will set the component_property of the button with the id 'continue1-button'. This is the value you need to return from the function. Has the condition occured that the button should not be disabled anymore end the function call with return False. Should the button still be disabled return True.

As for Problem 3 you would need to return 2 values because you have two outputs, for example return False, False if both dropdowns should be activated.


first of all I cant test the things I'm saying right now and I'm no expert either, but maybe my two cents will help you :)

  1. Are you actually returning the values? I guess you do, but just to be certain.
  2. Problem: I dont know if it fixes the problem, but your if's do the same thing and are always right. Either conditions_read is the string or not.
  3. Problem: I GUESS that there is no else statement, therefore NONE is returned and NONE resolves to False, therefore it seems as if the if statement was true.
  4. Problem: I'm not sure. You talk about 3 dropdowns, but in your code are only two. Maybe you are not returning the disabled1 and disabled2 and therefore again only NONE is returned and only one gets activated
Related