Skip to content

[Feature Request] Add optional delay to dcc.Loading() #2147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
halemade opened this issue Jul 18, 2022 · 3 comments
Closed

[Feature Request] Add optional delay to dcc.Loading() #2147

halemade opened this issue Jul 18, 2022 · 3 comments

Comments

@halemade
Copy link

Is your feature request related to a problem? Please describe.
Wrapping a dcc.Loading component around charts and have noticed that the loading animation occurs after every filter change as well as the initial load. While this is good if the filter change takes more than a second or two, we would like it if the component did not kick in if the load time was < 1/2 seconds.

Describe the solution you'd like
A delay argument in the dcc.Loading component that will engage the Loader only after a given amount of time.

Describe alternatives you've considered
CSS is an alternative, but a delay argument would be helpful for Python devs

@CNFeffery
Copy link
Contributor

@halemade Maybe you can use AntdSpin in my dash components library fac, it has a parameter delay, install it via pip install feffery_antd_components, here is a simple demo from my documents website:

demo

import feffery_antd_components as fac

fac.AntdSpace(
    [
        fac.AntdButton('触发耗时0.5秒的回调过程', id='spin-delay-demo-input1', type='primary'),
        fac.AntdButton('触发耗时2秒的回调过程', id='spin-delay-demo-input2', type='primary')
    ]
),

fac.AntdSpin(
    fac.AntdText('0.5秒回调 nClicks: 0', id='spin-delay-demo-output1', strong=True),
    delay=1000,
    text='回调中'
),

fac.AntdSpin(
    fac.AntdText('2s回调 nClicks: 0', id='spin-delay-demo-output2', strong=True),
    delay=1000,
    text='回调中'
)
...
@app.callback(
    Output('spin-delay-demo-output1', 'children'),
    Input('spin-delay-demo-input1', 'nClicks'),
    prevent_initial_call=True
)
def spin_delay_callback_demo1(nClicks):
    import time
    time.sleep(0.5)

    return f'0.5秒回调 nClicks: {nClicks}'


@app.callback(
    Output('spin-delay-demo-output2', 'children'),
    Input('spin-delay-demo-input2', 'nClicks'),
    prevent_initial_call=True
)
def spin_delay_callback_demo2(nClicks):
    import time
    time.sleep(2)

    return f'2秒回调 nClicks: {nClicks}'

@grawfin
Copy link

grawfin commented Jul 8, 2023

I second this.

The loading component is basically incompatible with some other components (for instance dash_bootstrap_components.TextArea or dcc.Input on beefier applications) since every time you begin typing you may trigger a change in loading state for a brief moment, and then you're cursor is no longer focused on the element you were typing in .... as an example.

@Coding-with-Adam
Copy link
Contributor

closed by #2760

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants