Skip to main content

Streamlit AutoComplete ComboBox

Project description

st-combobox


A streamlit custom component providing a combobox with autocomplete.

Example

Installation

pip install st-combobox

Overview

Create a combobox component and pass a search_function that accepts a str searchterm. The combobox is triggered on user input and calls the search function for new options.`.

You can either pass a list of arguments, e.g.

import wikipedia
from st_combobox import st_combobox

# function with list of labels
def search_wikipedia(searchterm: str) -> List[any]:
    return wikipedia.search(searchterm) if searchterm else []


# pass search function to combobox
selected_value = st_combobox(
    search_wikipedia,
    key="wiki_combobox",
)

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 combobox you can pass the following arguments:

selected_value = st_combobox(
    search_function: Callable[[str], List[any]],
    reset_function: Callable[[], None] = None,
    placeholder: str = "Search ...",
    label: str = None,
    default: any = None,
    clear_on_submit: bool = False,
    key: str = "combobox",
    rerun_on_update: bool = False,
    stop_on_update: bool = False,
    blank_search_value: str = None,
    return_only_on_submit: bool = False,
)

Explanations of the arguments

Function that will be called on user input

search_function: Callable[[str], List[any]]

Function that will be called when the combobox is reset.

reset_function: Callable[[], None] = None

Placeholder text when the combobox is blank.

placeholder: str = "Search ..."

Label shown above the component. If None, no label is shown.

label: str = None

Default return value in case nothing was submitted or the combobox cleared.

default: any = None

Automatically clear the input after selection.

clear_on_submit: bool = False

Streamlit key for unique component identification.

key: str = "combobox"

If true, will call st.rerun() on each search keystroke. If this is set to its default (False), the auto-complete results will always be one keystroke behind.

rerun_on_update: bool = False

If true (and rerun_on_update is false), will call st.stop() on each search keystroke.

stop_on_update: bool = False

If not None, will set the default search value when the box is initialized or reset.

blank_search_value: str = None

If true, will only return a non None value when the user selects an option. Otherwise, will keep returning the last value.

return_only_on_submit: bool = False

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 --legacy-peer-deps 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

st_combobox-1.2.0.tar.gz (654.0 kB view details)

Uploaded Source

Built Distribution

st_combobox-1.2.0-py3-none-any.whl (661.3 kB view details)

Uploaded Python 3

File details

Details for the file st_combobox-1.2.0.tar.gz.

File metadata

  • Download URL: st_combobox-1.2.0.tar.gz
  • Upload date:
  • Size: 654.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for st_combobox-1.2.0.tar.gz
Algorithm Hash digest
SHA256 75d2f26cbc3f6a365cc78ab9ce10e82dfc8086912573b1d366096d8be0a893e9
MD5 052d8f918a7b8200e2bcc1aaae4569f0
BLAKE2b-256 93acb6a0ab5794b21b123377f6a9ba96c39059c16702b278768021f4cdb4542c

See more details on using hashes here.

File details

Details for the file st_combobox-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: st_combobox-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 661.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for st_combobox-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7533f1afd10ebd8015fc9ed9fd704417146039e2a7d9846edee59da5aabc7eeb
MD5 fe36d6dbd7de557edd3a1600b6963231
BLAKE2b-256 37df74348d9fc3b95fda63602130c941ec0a75871d8447d9d16c8b9e5c1dbbc9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page