Skip to content
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

Adding debounce to self.param.update #984

Open
ahuang11 opened this issue Dec 3, 2024 · 2 comments
Open

Adding debounce to self.param.update #984

ahuang11 opened this issue Dec 3, 2024 · 2 comments
Labels
status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues. type-feature Feature request

Comments

@ahuang11
Copy link
Contributor

ahuang11 commented Dec 3, 2024

I would like a built-in mechanism in the self.param.update method (or similar) that supports debouncing. https://www.geeksforgeeks.org/debouncing-in-javascript/

Example:

  1. The code waits for 2 seconds before showing the loading icon.
  2. If the process completes or the event resolves within those 2 seconds, the icon is never shown.
  3. If the process doesn't complete, the icon appears after the delay, signaling that something is still loading.

This feature could be particularly useful for applications with frequent, rapid user interactions that trigger parameter updates (e.g., sliders or live data streams). It would improve the UX by removing flicker.

Use case would be linking widgets with self.state.param.busy, but at the current moment it could cause flickering:
holoviz/lumen#783 (comment)

I think it would be implemented here https://github.com/holoviz/param/blob/main/param/parameterized.py#L2297-L2357

@hoxbro
Copy link
Member

hoxbro commented Dec 4, 2024

I don't think this functionality should live in Param. I do think we should have some way to make the busy toggle not flicker on/off with a debounce, though I think this functionality should live in Panel.

@maximlt
Copy link
Member

maximlt commented Feb 11, 2025

I'm not sure what the right solution is for the Panel issue reported here.

I think however that adding debouncing to Param could be a good fit as Param supports async callbacks. I'm not entirely sure why the suggestion is for self.param.update, I'd see it more as a new keyword added to .param.watch.

import panel as pn

w_search = pn.widgets.TextInput(name='Search ...')
p_resuls = pn.MarkDown()

async def expensive_search(event):
    p_resuls.value = await db.query(...)

w_search.param.watch(expensive_search, 'value_input', debounce=3000)
pn.Column(w_search, p_resuls).servable()

@ahuang11 I wouldn't be surprised if that's a feature that was already implemented somehow in Panel for its internal needs. If that's really the case, that could motivate even more so implementing it in Param (many of the features of Param were first implemented in Panel).

I think it would be implemented here https://github.com/holoviz/param/blob/main/param/parameterized.py#L2297-L2357

@ahuang11 this link no longer points to the right lines.

@maximlt maximlt added type-feature Feature request status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues. labels Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues. type-feature Feature request
Projects
None yet
Development

No branches or pull requests

3 participants