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.2.tar.gz
(586.8 kB
view hashes)
Built Distribution
Close
Hashes for streamlit-flexselect-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a96dd3dc9ba4abb73ca16f46167cf63a2ffdbb8f9d8d6a97b447d69a803415fe |
|
MD5 | 9a75fcd82bfd2b6900a541fa0e4eac71 |
|
BLAKE2b-256 | 89322b9f12477815e4a9a3c9aa39e1996aecf2dbf7746d1ccee69b40a67fd9bf |
Close
Hashes for streamlit_flexselect-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 685076a3df13e6d90037865b7cdc4a0ef24c1700d25ed3a893b6841b0288b189 |
|
MD5 | 3ffd45d0d498a40b1f348d5cdbd90ffd |
|
BLAKE2b-256 | 4b6c93ac1f6b2f95f891ba3a5225b2e26fb02e16384b078e442d9804aebef1dd |