A flexible multiselect that lets the user add custom elements
Project description
Streamlit FlexSelect
A flexible select component for Streamlit that allows users to select one or more options from a list. In addition to the given options, users can also add their own options dynamically.
Installation
Install streamlit-flexselect
via pip:
pip install streamlit-flexselect
Usage
To use flexselect
in your Streamlit app:
- First, import the component:
from streamlit_flexselect import flexselect
- Use the
flexselect
function in your Streamlit app:
selected_values = flexselect(
label="Your Component Label",
options=["Option 1", "Option 2", "Option 3"],
default_values=["Option 1"]
)
Parameters
label
(str): The label of the component.options
(List[str]): A list of options to choose from.default_values
(Optional[List[str]]): A list of default values to select. Defaults to None.key
(Optional[str]): An optional key to use for the component. Defaults to None.on_change
(Optional[Callable]): An optional callback function to execute when the component value changes. A key argument must be used to use the on_change The callback must acceptkey
as the first argument, and can accept more arguments. To accept these additional arguments, you need to passargs
/kwargs
to the component. Defaults to None.args
(Optional[List]): An optional list of arguments to pass to the callback function. Defaults to None.kwargs
(Optional[Dict]): An optional dictionary of keyword arguments to pass to the callback function. Defaults to None.
Examples
Simple Example
Here's a simple example of how to use flexselect
in a Streamlit app:
import streamlit as st
from streamlit_flexselect import flexselect
def main():
st.title("Streamlit FlexSelect Simple Example")
selected_values = flexselect(
label="Select your favorite fruits",
options=["Apple", "Orange", "Banana", "Grapes"],
default_values=["Apple"]
)
st.write(f"You selected: {', '.join(selected_values)}")
if __name__ == "__main__":
main()
Example with on_change Callback
Here's an example that uses the on_change
callback to write the selected elements using st.session_state[key]
, and the arguments and keyword arguments:
import streamlit as st
from streamlit_flexselect import flexselect
def on_change_callback(key, *args, **kwargs):
selected_elements = st.session_state[key]
st.write(f"Selected elements:", selected_elements)
st.write(f"Args: {args}")
st.write(f"Kwargs: {kwargs}")
def main():
st.title("Streamlit FlexSelect Callback Example")
selected_values = flexselect(
label="Select your favorite fruits",
options=["Apple", "Orange", "Banana", "Grapes"],
default_values=["Apple"],
on_change=on_change_callback,
key='flexselect'
)
if __name__ == "__main__":
main()
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
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
streamlit-flexselect-0.0.4.tar.gz
(586.7 kB
view hashes)
Built Distribution
Close
Hashes for streamlit-flexselect-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | abf8fad3e2dc7ba5a0b7c4296d6fb6c5fe9ca76a5aab0c706ce2eddc5e17f64a |
|
MD5 | 4a1b7288a8c89e1ab891c472825ffe3a |
|
BLAKE2b-256 | 785cd0595cd76e4c986208b02343fae6a32d0b5757d29d9dd552951a1ba64411 |
Close
Hashes for streamlit_flexselect-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e97e2362a88c9bd48322a9426626f0a481840ae0f4a8e0783c3a9dd90fc06e9b |
|
MD5 | 93db9c401d9a1db0b9da1070a756505c |
|
BLAKE2b-256 | b1e5b6ed94bf203d540b595621944a454e462b1a03b32a6d05853a0fd91edf94 |