question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Keyboard shortcuts

See original GitHub issue

Problem

I’m more productive when I can use keyboard shortcuts. E.g. press left/right to move to previous / next image. Press space to toggle some viz. Press j/k to move up/down some slider.

Solution

MVP: Provide a way to map 80% of the keys to custom actions. It could be an optional argument to streamlit.button, streamlit.slider (two keys for up/down one step), etc.

Possible additions: Allow to map most keys, inclluding remapping ‘c’ which currenty clears the streamlit cache.

Additional context

Comes form personal need. Also mentioned here: https://discuss.streamlit.io/t/idea-keyboard-bindings/1976 .


Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:25
  • Comments:28 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
brunomsantiagocommented, Jan 26, 2022

Small update, I continued looking for ways to make @andfanilo hacky solution more robust and I think it is good enough now. Now I get the buttons based on their labels. First I get all buttons then check their labels until I find the desired button. Here is the code of the full proof of concept, also published in a gist

import streamlit as st
import streamlit.components.v1 as components


def left_callback():
    st.write('Left button was clicked')


def right_callback():
    st.write('Right button was clicked')


left_col, right_col, _ = st.columns([1, 1, 3])

with left_col:
    st.button('LEFT', on_click=left_callback)

with right_col:
    st.button('RIGHT', on_click=right_callback)

components.html(
    """
<script>
const doc = window.parent.document;
buttons = Array.from(doc.querySelectorAll('button[kind=primary]'));
const left_button = buttons.find(el => el.innerText === 'LEFT');
const right_button = buttons.find(el => el.innerText === 'RIGHT');
doc.addEventListener('keydown', function(e) {
    switch (e.keyCode) {
        case 37: // (37 = left arrow)
            left_button.click();
            break;
        case 39: // (39 = right arrow)
            right_button.click();
            break;
    }
});
</script>
""",
    height=0,
    width=0,
)

6reactions
louislvacommented, Feb 11, 2022

Hey @albusdemens and @Pashtetickus. Apologies for the delayed response.

You can uninstall your current streamlit, then download this whl I built and install it: https://github.com/louislva/streamlit/blob/develop/builds/streamlit-1.3.2-py2.py3-none-any.whl

That way you don’t have to set up the build environment. Hope it’s helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chromebook keyboard shortcuts - Google Help
Tabs and windows ; Open a new window, Ctrl + n ; Open a new window in Incognito mode, Shift + Ctrl +...
Read more >
Mac keyboard shortcuts - Apple Support
On keyboards made for Windows PCs, use the Alt key instead of Option, and the Windows logo key instead of Command. Some keys...
Read more >
Keyboard Shortcuts - W3Schools
Basic Shortcuts ; Edit menu, Alt + E · Ctrl + F2 + F ; File menu, Alt + F · Ctrl +...
Read more >
Table of keyboard shortcuts - Wikipedia
In computing, a keyboard shortcut is a sequence or combination of keystrokes on a computer keyboard which invokes commands in software.
Read more >
Tech Savvy Tips and Tricks: Keyboard Shortcuts
Internet shortcuts · Ctrl+F: Find a word or phrase in the current webpage. · Ctrl+T: Open a new browser tab. · Ctrl+N: Open...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found