Name | streamlit-flexselect JSON |
Version |
0.0.6
JSON |
| download |
home_page | |
Summary | A flexible multiselect that lets the user add custom elements |
upload_time | 2023-12-06 13:49:11 |
maintainer | |
docs_url | None |
author | Dvir Itzkovits |
requires_python | >=3.7 |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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:
```bash
pip install streamlit-flexselect
```
## Usage
To use `flexselect` in your Streamlit app:
1. First, import the component:
```python
from streamlit_flexselect import flexselect
```
2. Use the `flexselect` function in your Streamlit app:
```python
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.
- `add_missing_defaults` (bool): If True, will add any default values that are not in the options list to the options list. Defaults to False.
- `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 accept `key` as the first argument, and can accept more arguments. To accept these additional arguments, you need to pass `args`/`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:
```python
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:
```python
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()
```
### Example with add_missing_defaults
Sometimes we might want to add defeault options in our app, but let the user chose their own options as well. In this case, we can use the `add_missing_defaults` parameter to add any default values that are not in the options list to the options list. Here's an example:
```import streamlit as st
from streamlit_flexselect import flexselect
def main():
st.title("Streamlit FlexSelect Example with add_missing_defaults")
default_values = get_default_values_from_user() # This is some function that gets a list of values from the user
selected_values = flexselect(
label="Select your favorite fruits",
options=["Apple", "Orange", "Banana", "Grapes"],
default_values=default_values,
add_missing_defaults=True
)
st.write(f"You selected: {', '.join(selected_values)}")
if __name__ == "__main__":
main()
```
## Contributing
Contributions are welcome! Please open an issue or submit a pull request on [GitHub](<link-to-your-repo>).
Raw data
{
"_id": null,
"home_page": "",
"name": "streamlit-flexselect",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Dvir Itzkovits",
"author_email": "dvir.itzko@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/21/5c/1dd9935b8b54559a4a5914ff91988f6803163f2b33b435c9b18cf760cc48/streamlit-flexselect-0.0.6.tar.gz",
"platform": null,
"description": "# Streamlit FlexSelect\n\nA 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.\n\n## Installation\n\nInstall `streamlit-flexselect` via pip:\n\n```bash\npip install streamlit-flexselect\n```\n\n## Usage\n\nTo use `flexselect` in your Streamlit app:\n\n1. First, import the component:\n\n```python\nfrom streamlit_flexselect import flexselect\n```\n\n2. Use the `flexselect` function in your Streamlit app:\n\n```python\nselected_values = flexselect(\n label=\"Your Component Label\",\n options=[\"Option 1\", \"Option 2\", \"Option 3\"],\n default_values=[\"Option 1\"]\n)\n```\n\n## Parameters\n\n- `label` (str): The label of the component.\n- `options` (List[str]): A list of options to choose from.\n- `default_values` (Optional[List[str]]): A list of default values to select. Defaults to None.\n- `key` (Optional[str]): An optional key to use for the component. Defaults to None.\n- `add_missing_defaults` (bool): If True, will add any default values that are not in the options list to the options list. Defaults to False.\n- `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 accept `key` as the first argument, and can accept more arguments. To accept these additional arguments, you need to pass `args`/`kwargs` to the component. Defaults to None.\n- `args` (Optional[List]): An optional list of arguments to pass to the callback function. Defaults to None.\n- `kwargs` (Optional[Dict]): An optional dictionary of keyword arguments to pass to the callback function. Defaults to None.\n\n## Examples\n\n### Simple Example\n\nHere's a simple example of how to use `flexselect` in a Streamlit app:\n\n```python\nimport streamlit as st\nfrom streamlit_flexselect import flexselect\n\ndef main():\n st.title(\"Streamlit FlexSelect Simple Example\")\n\n selected_values = flexselect(\n label=\"Select your favorite fruits\",\n options=[\"Apple\", \"Orange\", \"Banana\", \"Grapes\"],\n default_values=[\"Apple\"]\n )\n\n st.write(f\"You selected: {', '.join(selected_values)}\")\n\nif __name__ == \"__main__\":\n main()\n```\n\n### Example with on_change Callback\n\nHere'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:\n\n```python\nimport streamlit as st\nfrom streamlit_flexselect import flexselect\n\ndef on_change_callback(key, *args, **kwargs):\n selected_elements = st.session_state[key]\n st.write(f\"Selected elements:\", selected_elements)\n st.write(f\"Args: {args}\")\n st.write(f\"Kwargs: {kwargs}\")\n\ndef main():\n st.title(\"Streamlit FlexSelect Callback Example\")\n\n selected_values = flexselect(\n label=\"Select your favorite fruits\",\n options=[\"Apple\", \"Orange\", \"Banana\", \"Grapes\"],\n default_values=[\"Apple\"],\n on_change=on_change_callback,\n key='flexselect'\n )\n\nif __name__ == \"__main__\":\n main()\n```\n\n### Example with add_missing_defaults\nSometimes we might want to add defeault options in our app, but let the user chose their own options as well. In this case, we can use the `add_missing_defaults` parameter to add any default values that are not in the options list to the options list. Here's an example:\n\n```import streamlit as st\nfrom streamlit_flexselect import flexselect\n\ndef main():\n st.title(\"Streamlit FlexSelect Example with add_missing_defaults\")\n\n default_values = get_default_values_from_user() # This is some function that gets a list of values from the user\n selected_values = flexselect(\n label=\"Select your favorite fruits\",\n options=[\"Apple\", \"Orange\", \"Banana\", \"Grapes\"],\n default_values=default_values,\n add_missing_defaults=True\n )\n\n st.write(f\"You selected: {', '.join(selected_values)}\")\n\nif __name__ == \"__main__\":\n main()\n```\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request on [GitHub](<link-to-your-repo>).\n",
"bugtrack_url": null,
"license": "",
"summary": "A flexible multiselect that lets the user add custom elements",
"version": "0.0.6",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0775afc9cca58d69527ade24ee1d3926730243709a6089763766a78200af4815",
"md5": "491e01e42586f291d4e66c1e9460884c",
"sha256": "44c1d21b2973f701ca033460d96b5f34f8a18e55416a3ab8e9b600b4d203967d"
},
"downloads": -1,
"filename": "streamlit_flexselect-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "491e01e42586f291d4e66c1e9460884c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 1150431,
"upload_time": "2023-12-06T13:49:08",
"upload_time_iso_8601": "2023-12-06T13:49:08.055913Z",
"url": "https://files.pythonhosted.org/packages/07/75/afc9cca58d69527ade24ee1d3926730243709a6089763766a78200af4815/streamlit_flexselect-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "215c1dd9935b8b54559a4a5914ff91988f6803163f2b33b435c9b18cf760cc48",
"md5": "a11512ae70f8555d32b48d04159a9123",
"sha256": "e7b34846159d8a2d773e104fa446d322038497b351f1881c936db0bfb578d2ad"
},
"downloads": -1,
"filename": "streamlit-flexselect-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "a11512ae70f8555d32b48d04159a9123",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 587741,
"upload_time": "2023-12-06T13:49:11",
"upload_time_iso_8601": "2023-12-06T13:49:11.646483Z",
"url": "https://files.pythonhosted.org/packages/21/5c/1dd9935b8b54559a4a5914ff91988f6803163f2b33b435c9b18cf760cc48/streamlit-flexselect-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-06 13:49:11",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "streamlit-flexselect"
}