You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to be able to capture keypresses and use them for callbacks. This could be used to make keyboard shortcuts in place of buttons.
Reacted by Elias Dabbas, Ben Dichter, Olof Harrysson, Konstantin Miller, Kyle King, Conchylicultor, AIQC, Shaun Irwin, Randy Creasi, Heptazhou and 3 more
@emilhe Thanks for pointing out dash-extensions - lots of good stuff there! Some overlap with functionality we're already working on (eg flattened callback args #1180) and other things we haven't started on but have discussed. In particular Trigger#1054 is something we're very interested in adding to Dash itself, and Keyboard would be a great addition to dash-core-components. You're of course welcome to continue developing these features separately under dash-extensions but if you're interested to PR the more generally-applicable features into Dash or dash-core-components directly, we'd be glad to help 😎
@alexcjohnson Thanks! As the components mature, i think it would be good (in particular for new users), if they were moved to dash-core-components. The Trigger component would probably be a good place to start (it is pretty simple), but i feel (based on community feedback) that the functionality provided by the Download and ServersideOutput components are even more needed. When i find some time, i'll take a look at the contribution guidelines :)
The Keyboard component was removed in favor of the more general EventListener component. While the latter does have feature parity (and beyond), the syntax is a bit more convoluted, so I am starting to rethink if I made the right decision.
Feeling the same. Capturing the keyboard event should have been much easier. I am writing a local application with dash because of the good support of Cytoscape. But maybe it would have been much easier if I simply used QT.
I've succeeded in applying the EventListener from dash extensions. For those who'd need, here's an example code I use to capture Return key hits on a couple of Mantine Inputs:
fromdashimportdcc, html, callback, Input, Output, State, ctx, no_updatefromdash.exceptionsimportPreventUpdateimportdash_mantine_componentsasdmcfromdash_iconifyimportDashIconifyfromdash_extensionsimportEventListener# CAPTURE ONLY KEY PRESSESevents= [{'event': 'keydown', 'props': ['key']}]
# THE INPUTSinput_login=EventListener(dmc.TextInput(label='', id='login__input_login', placeholder='Username', radius='lg', icon=[DashIconify(icon='bxs:user', width=20)],
size='md', style={'margin': '0% 1%'}), id='login__input_login_events', events=events)
input_password=EventListener(dmc.PasswordInput(label='', id='login__input_password', placeholder='Password', radius='lg', icon=[DashIconify(icon='bxs:lock-alt', width=20)],
size='md', style={'margin': '0% 1%'}), id='login__input_password_events', events=events)
#======================== MAIN LAYOUT ========================#deflayout():
# there are also other components here, but I've cut them away for clarity...returnhtml.Div([dmc.LoadingOverlay(dmc.Stack([input_login, input_password],
justify='center', align='stretch', spacing='lg'))],
style={'margin': '10% 30%'})
#======================== CALLBACKS ========================#@callback(output={'hi_user_value': Output('login__hi_user', 'children'),'alert_err_value': Output('login__alert_error', 'children'),'alert_err_hidden': Output('login__alert_error', 'hide'),'div_admin_action_hidden': Output('login__div_admin_actions', 'hidden'),'div_logged_in_hidden': Output('login__div_logged_in', 'hidden'),'div_login_hidden': Output('login__div_login', 'hidden') },inputs=[Input('login__input_login_events', 'n_events'), # login input keydown event countInput('login__input_password_events', 'n_events'), # password input keydown event countState('login__input_login', 'value'), # login valueState('login__input_password', 'value'), # password valueState('login__input_login_events', 'event'), # login input keydown eventState('login__input_password_events', 'event') # password input keydown event ])defupdate_layout(login_nevents, password_nevents, in_login, in_password, login_event, password_event):
# get trigger source, return if none fired_id=ctx.triggered_idifnotfired_id:
raisePreventUpdate# block updating if any other key was hit BUT the Enter key on either of the two inputsif (fired_id=='login__input_password_events'and (notpassword_neventsorpassword_event.get('key', '') !='Enter')) or \
(fired_id=='login__input_login_events'and (notlogin_neventsorlogin_event.get('key', '') !='Enter')):
raisePreventUpdate# Enter was pressed on login inputlogin_return=fired_id=='login__input_login_events'andlogin_nevents# Enter was pressed on password inputpassw_return=fired_id=='login__input_password_events'andpassword_neventsiflogin_returnorpassw_return:
# do login stuff ...raisePreventUpdate
BTW there's no need to wrap your dash app in dash_extensions.enrich.DashProxy (as suggested in the docs example). Mine works like a charm on a bare dash app.
Reacted by Milan Mitrovic, KJ, cekarius and Fabian Indrunas
Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are most important to our community. If this issue is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. (Please note that we will give priority to reports that include a short reproducible example.) If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson
Activity
Jaudouard commentedon May 18, 2019
Perhaps a hidden input field with autofocus on ?
You would have several callbacks listening to this input and executing code accordingly.
I guess you would have to add an extra callback dedicated to clearing the input field everytime it is filled with something as well.
mflevine commentedon May 20, 2019
Seems pretty hacky this way. Wont the input field lose focus as soon as the user starts interacting with other inputs?
Jaudouard commentedon May 21, 2019
You are right, pretty hacky...
konstantinmiller commentedon Jul 24, 2020
Oh, I'm a bit surprised. Is there no way one can create callbacks for keyboard events? That seems like a basic interaction pattern.
emilhe commentedon Jul 31, 2020
You could try the
Keyboardcomponent in dash-extensions,https://pypi.org/project/dash-extensions/
alexcjohnson commentedon Jul 31, 2020
@emilhe Thanks for pointing out
dash-extensions- lots of good stuff there! Some overlap with functionality we're already working on (eg flattened callback args #1180) and other things we haven't started on but have discussed. In particularTrigger#1054 is something we're very interested in adding to Dash itself, andKeyboardwould be a great addition todash-core-components. You're of course welcome to continue developing these features separately underdash-extensionsbut if you're interested to PR the more generally-applicable features into Dash ordash-core-componentsdirectly, we'd be glad to help 😎emilhe commentedon Aug 3, 2020
@alexcjohnson Thanks! As the components mature, i think it would be good (in particular for new users), if they were moved to
dash-core-components. TheTriggercomponent would probably be a good place to start (it is pretty simple), but i feel (based on community feedback) that the functionality provided by theDownloadandServersideOutputcomponents are even more needed. When i find some time, i'll take a look at the contribution guidelines :)Allow projects to use dcc source directly (plotly#723)
Allow projects to use dcc source directly (#723)
aiqc commentedon Aug 2, 2022
Hmm looks like the
Keyboardclass got dropped fromdash_extensions.Not seeing it in their docs
aiqc commentedon Aug 2, 2022
Related:
emilhe commentedon Aug 3, 2022
The
Keyboardcomponent was removed in favor of the more generalEventListenercomponent. While the latter does have feature parity (and beyond), the syntax is a bit more convoluted, so I am starting to rethink if I made the right decision.https://www.dash-extensions.com/pages/components/event-listener
phsamuel commentedon Sep 15, 2022
Feeling the same. Capturing the keyboard event should have been much easier. I am writing a local application with dash because of the good support of Cytoscape. But maybe it would have been much easier if I simply used QT.
S0mbre commentedon Oct 19, 2022
I've succeeded in applying the
EventListenerfromdash extensions. For those who'd need, here's an example code I use to capture Return key hits on a couple of Mantine Inputs:BTW there's no need to wrap your dash
appindash_extensions.enrich.DashProxy(as suggested in the docs example). Mine works like a charm on a bare dashapp.ndrezn commentedon Mar 20, 2024
@hannahker, how did PS do this for the LBL project?
hannahker commentedon Mar 20, 2024
The
dash-extensionsEventListenerworks like a charm for this! Similar to @S0mbre, you define as :Then you can attach callbacks using
Input("keybind-event-listener", "event")gvwilson commentedon Jul 25, 2024
Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are most important to our community. If this issue is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. (Please note that we will give priority to reports that include a short reproducible example.) If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson