Function that executes app.callbacks

I wrote a function that has an app.callback that enables/disables a component. This function takes 4 arguments: output component, output component value, input component, input component.

def condition_checker(field_value):
    '''Check if the value of a field is None. Return True if the field is None'''
    if field_value is None:
        return True
    return False

def enable_disable(out_comp, out_comp_value, in_comp, in_comp_value):
    '''The value pass to output is only True or False'''
    @app.callback(Output(out_comp, out_comp_value), [Input(in_comp, in_comp_value)])
    def enable_component(variable):
        '''Out_comp is enabled when variable is not None'''
        return condition_checker(in_comp_value)

If I were to call this function to enable or disable a component:

enable_disable('comp1', 'disabled', 'comp2', 'value')

This seems to not work but the callback graph in my app is correct. Has anyone tried this before?

Thanks

Not sure if I am understanding this correctly, but I don’t think a callback inside a function would work since the function is not “listening” in the same way a callback does. Can’t you have the following structure:

@callback(input(variable True False))
function()
if True:
return whatever you need when
if False:
return Normal

1 Like