Streamlit Keyup Input
Streamlit-keyup is a custom component for Streamlit applications that provides a text input field which updates its value in real-time, on every key press (on keyup event). This differs from Streamlit's native `st.text_input` which typically waits for the user to press Enter or for the widget to lose focus. The library is currently at version 0.3.0 and receives occasional updates, primarily for compatibility and minor fixes.
Warnings
- gotcha The `disabled` argument did not update dynamically in versions prior to `0.3.0`, meaning its initial state would persist even if changed programmatically. This was fixed in `v0.3.0`.
- gotcha Compatibility issues can arise with specific Streamlit versions. For example, `v0.2.4` addressed a rendering issue with Streamlit `1.32.2`.
- gotcha The `key` parameter is essential for Streamlit components to maintain their state across reruns. While `streamlit-keyup` generates a default key if none is provided, explicitly setting unique keys for each `st_keyup` instance is a best practice to prevent unexpected behavior and component state collisions.
- deprecated New arguments like `max_chars`, `type`, `placeholder`, `disabled`, `label_visibility` were introduced in `v0.2.0`, and `on_change` in `v0.1.8`. While not strictly breaking, code written for older versions will not leverage these new functionalities. Review your usage if upgrading from significantly older versions.
Install
-
pip install streamlit-keyup
Imports
- st_keyup
from st_keyup import st_keyup
Quickstart
import streamlit as st
from st_keyup import st_keyup
st.title("Streamlit Keyup Demo")
# Basic usage: value updates after every key press
value_basic = st_keyup("Enter text here", key="keyup_basic")
st.write(f"Basic Input: {value_basic}")
# Usage with a default value
value_with_default = st_keyup("Enter with default", value="Hello world", key="keyup_default")
st.write(f"Input with default: {value_with_default}")
# Usage with debounce to limit update frequency (e.g., update every 500ms)
value_debounced = st_keyup("Enter with debounce", debounce=500, key="keyup_debounced")
st.write(f"Debounced Input: {value_debounced}")
# Example with max_chars, placeholder, and disabled
value_complex = st_keyup(
"Limited and Placeholder",
max_chars=10,
placeholder="Max 10 chars",
disabled=False, # Use os.environ.get for dynamic disable
key="keyup_complex"
)
st.write(f"Complex Input: {value_complex}")