Streamlit AutoComplete ComboBox
Project description
st-combobox
A streamlit custom component providing a searchbox with autocomplete.
Installation
pip install st-combobox
Overview
Create a searchbox component and pass a search_function
that accepts a str
searchterm. The searchbox is triggered on user input, calls the search function for new options and redraws the page via st.experimental_rerun()
.
You can either pass a list of arguments, e.g.
import wikipedia
from streamlit_searchbox import st_searchbox
# function with list of labels
def search_wikipedia(searchterm: str) -> List[any]:
return wikipedia.search(searchterm) if searchterm else []
# pass search function to searchbox
selected_value = st_searchbox(
search_wikipedia,
key="wiki_searchbox",
)
This example will call the Wikipedia Api to reload suggestions. The selected_value
will be one of the items the search_wikipedia
function returns, the suggestions shown in the UI components are a str
representation. In case you want to provide custom text for suggestions, pass a Tuple
.
def search(searchterm: str) -> List[Tuple[str, any]]:
...
Usage
To customize the searchbox you can pass the following arguments:
search_function: Callable[[str], List[any]]
Function that will be called on user input
placeholder: str = "Search ..."
Placeholder for empty searches shown within the component.
label: str = None
Label shown above the component.
default: any = None
Default return value in case nothing was submitted or the searchbox cleared.
clear_on_submit: bool = False
Automatically clear the input after selection.
key: str = "searchbox"
Streamlit key for unique component identification.
Example
An example Streamlit app can be found here
Build
If any changes were made to the frontend, go to st_combobox/frontend
and run npm run build
(npm install
if you don't have the packages on your machine). Then push the changes made to the frontend/build
folder to the repo.
You may need to follow this help if you run into issues while building.
Now all you have to do is make a release and the github action will push to PyPi (make sure setup.py
has a new verison)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for st_combobox-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ea2f526d9129b905ee2db421b6e7f4d1aacd0e577be6e8fa2f9fe843fb864c2 |
|
MD5 | 3eee8b755721fcb560d8d8600836802f |
|
BLAKE2b-256 | 81f694e0d09484238cf721880137da374931de8714b6838b3aa520b17f8dc239 |