Skip to content

Use of debounce or how to get the input evaluated only after Enter #612

@viogp

Description

@viogp

Hi,

I've looked to the documentation and didn't manage to do what I want: I have a box to enter text and I want to evaluate this text only after enter has been pressed (I don't want to evaluate while typing). It'll be even better if this evaluation is done after everytime Enter is press on that box. At the moment I get the following error, so clearly I'm not calling debounce properly (python 3.7.1, dash 0.35.1):

File "dash_layout.py", line 57, in <module>
    [Input(component_id='path2file-input',component_property='value',component_debounce=True)],
TypeError: __init__() got an unexpected keyword argument 'component_debounce'

Here is the code I have now:

@app.callback(Output(component_id='path2file-output',component_property='children'),
                [Input(component_id='path2file-input',component_property='value',component_debounce=True)],    
                [],
                [])
def path2file_callback(input_):
    global filename
    filename = input_
    return File_Info(filename)

And the messages:

def File_Info(filename):
    if (filename is None or filename == ""):
        return html.Div(
            id = 'path2file-output',
            children = [
                html.H5(
                    children=['No path to file has been input yet.'],
                    style={
                        'textAlign': 'center',
                        'color': colors['text'],
                        'fontFamily': 'Roboto Condensed',
                        'fontSize': '16',
                        'fontWeight': 'normal',
                    }
                ),
            ])
    else:
        problem, tester = test_file(filename)
        
        if problem:
            return html.Div(
                id = 'path2file-output',
                children = [
                    html.H5(
                        children=['There was an error processing ',filename],
                        style={
                            'textAlign': 'center',
                            'color': colors['text'],
                            'fontFamily': 'Roboto Condensed',
                            'fontSize': '16',
                            'fontWeight': 'normal',
                        }
                    ),
                ])
        else:
            return html.Div(
                id = 'path2file-output',
                children = [
                    html.H5(
                        children=['File: ',filename],
                        style={
                            'textAlign': 'center',
                            'color': colors['text'],
                            'fontFamily': 'Roboto Condensed',
                            'fontSize': '16',
                            'fontWeight': 'normal',
                        }
                    ),
                    html.H5(
                        children=['Tester type: ',tester],
                        style={
                            'textAlign': 'center',
                            'color': colors['text'],
                            'fontFamily': 'Roboto Condensed',
                            'fontSize': '16',
                            'fontWeight': 'normal',
                        }
                    ),
                ])

Thanks fo rany help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions