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.3.tar.gz
(586.8 kB
view hashes)
Built Distribution
Close
Hashes for streamlit-flexselect-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a12be04b9d853b725f3295f9f10b2bd8b70974f1532d36bdd94c9a0e36037970 |
|
MD5 | 93edeb8e727ae3a3f0c953d63b8bd9e6 |
|
BLAKE2b-256 | 11fef632649f84adfa1cd10de4c5eb48753b469cd34ff606576eeaad64305336 |
Close
Hashes for streamlit_flexselect-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e84c4fd2837a3371762c3d47108c1e9e633c8372de8ed0ad454d72e0ca3411f6 |
|
MD5 | 5a30bcc033302b928b8ee8d6124ae438 |
|
BLAKE2b-256 | 23ce62114bda6624ecf5a55e5aac2eb43ac091a52ea68ffcab2bbfa21866f443 |