continuously perform operation while button held
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 24.4k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 13
Description
Feature: while button held
Is your feature request related to a problem? Please describe.
I have been trying to integrate dash into applications to control servos or motors. I am trying to integrate dash to continuously perform an operation while the button is held down.
Describe the solution you'd like
Support for an options in callbacks for buttons being held down would be great for this. I first thought of having the number of clicks continually increase as the button is held down would solve this but the n_clicks component does not update until the button is released.
The idea I have would be a component property like n_clicks but called n_down or something that returns a boolean to represent if the button is held down or not. This component in the callback would continuously trigger the callback as the button is held down.
Describe alternatives you've considered
A way around this which would be a temporary fix would be to integrate keyboard input so that you would not need to use dash for this. This seems like a good idea, but on devices which are touch based like smartphones/tablets this would not work.
Another alternative I would considered is using javascript to complete this, though this would prevent me from using the python libraries used to control the motors. Here and here are implementations of a js solution.
Additional context
Here is an example that might make my idea more clear.
@app.callback(
Output('item_id', 'children'),
Input('button_id', 'n_down')
)
def while_button_held(button_state):
if button_state == True:
print('do something here because the button is held down')
return ''
else:
print('the button is not held down')
return ''
Another example:
@app.callback(
Output('item_id', 'children'),
Input('button_id', 'n_down')
)
def while_button_held(button_state):
while button_state:
print('do something here because the button is held down')
print('the button is no longer held down')
return ''
I understand that dash is mostly used for data and for graphing, but I think that something like this may help it expand more into the HMI and automation space which could add a ton of benefit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is named. Start by tracing how button n_clicks reaches Python callbacks and compare that behavior with the proposed n_down state and callback examples; done would require agreed press, hold, and release semantics plus tests for them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- full-stack
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100