st-repeating-field-group


Namest-repeating-field-group JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/joey12725/st-repeating-field-group
SummaryA Streamlit plugin for creating repeating field groups
upload_time2024-09-03 20:40:15
maintainerNone
docs_urlNone
authorJoey Hersh
requires_python>=3.7
licenseNone
keywords streamlit plugin repeating field group
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # st-repeating-field-group

A Streamlit plugin for creating dynamic, repeating field groups with add/remove functionality and conditional field display.

## Installation

Install the package using pip:

```bash
pip install st-repeating-field-group
```

## Features

- Create repeating groups of form fields
- Dynamically add and remove field groups
- Support for various field types: text, number, date, checkbox, toggle, slider, range slider, and dropdown
- Conditional field display based on other field values
- Customizable default values

## Usage

### Basic Usage

Here's a simple example of how to use the `generate_repeating_field_group` function:

```python
import streamlit as st
from st_repeating_field_group import generate_repeating_field_group

keys = {
    "name": {"type": str, "default": ""},
    "age": {"type": int, "default": 0},
    "is_student": {"type": "checkbox", "default": False}
}

group_id = "example_group"
default_values = [
    {"name": "John Doe", "age": 30, "is_student": False},
    {"name": "Jane Smith", "age": 25, "is_student": True}
]

rows = generate_repeating_field_group(keys, group_id, default_values)

st.write(rows)
```

### Advanced Usage with Conditional Fields and Range Slider

You can use the `only_show_if` parameter to conditionally display fields based on the values of other fields in the same group. Here's an example that also includes a range slider:

```python
import streamlit as st
from st_repeating_field_group import generate_repeating_field_group

keys = {
    "name": {"type": str, "default": ""},
    "age": {"type": int, "default": 0},
    "is_student": {"type": "checkbox", "default": False},
    "school_name": {
        "type": str,
        "default": "",
        "only_show_if": {
            "kwargs": {"is_student": "is_student"},
            "func": lambda is_student: is_student
        }
    },
    "job_title": {
        "type": str,
        "default": "",
        "only_show_if": {
            "kwargs": {"is_student": "is_student"},
            "func": lambda is_student: not is_student
        }
    },
    "salary_range": {
        "type": "range_slider",
        "default": (30000, 80000),
        "min": 0,
        "max": 200000,
        "step": 1000,
        "only_show_if": {
            "kwargs": {"is_student": "is_student"},
            "func": lambda is_student: not is_student
        }
    }
}

group_id = "advanced_example_group"
default_values = [
    {"name": "John Doe", "age": 30, "is_student": False, "job_title": "Engineer", "salary_range": (50000, 100000)},
    {"name": "Jane Smith", "age": 25, "is_student": True, "school_name": "University XYZ"}
]

rows = generate_repeating_field_group(keys, group_id, default_values)

st.write(rows)
```

In this example, the "school_name" field will only be displayed if "is_student" is checked, while the "job_title" and "salary_range" fields will only be displayed if "is_student" is not checked.

### Supported Field Types

The `generate_repeating_field_group` function supports the following field types:

- `str` or `"str"`: Text input
- `int` or `"int"`: Integer input
- `float` or `"float"`: Float input
- `"choice"`: Dropdown selection
- `"date"`: Date input
- `"toggle_switch"`: Toggle switch
- `"checkbox"`: Checkbox
- `"slider"`: Slider input
- `"range_slider"`: Range slider input

### Parameters

- `keys` (dict): A dictionary defining the fields and their properties.
- `group_id` (str): A unique identifier for the field group.
- `default_values` (list, optional): Default values for the fields.

#### Field Properties

Each field in the `keys` dictionary can have the following properties:

- `type`: The data type or input type of the field (required).
- `default`: The default value for the field (required).
- `choices`: A list of options for dropdown fields (required for "choice" type).
- `min`: Minimum value for numeric or slider fields (optional).
- `max`: Maximum value for numeric or slider fields (optional).
- `step`: Step size for numeric or slider fields (optional).
- `only_show_if`: A dictionary containing conditional display logic (optional).

#### Using `only_show_if`

The `only_show_if` property allows you to conditionally display fields based on the values of other fields in the same group. It has two sub-properties:

- `kwargs`: A dictionary mapping parameter names to field names in the current group.
- `func`: A function that takes the mapped field values as arguments and returns a boolean indicating whether the field should be displayed.

Example:

```python
"school_name": {
    "type": str,
    "default": "",
    "only_show_if": {
        "kwargs": {"is_student": "is_student"},
        "func": lambda is_student: is_student
    }
}
```

In this example, the "school_name" field will only be displayed if the "is_student" checkbox is checked.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/joey12725/st-repeating-field-group",
    "name": "st-repeating-field-group",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "streamlit plugin repeating field group",
    "author": "Joey Hersh",
    "author_email": "joeyandpaige@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7d/ea/b5819523c238db8adf2118f0502235178a2f54f676620f28b18ad639904e/st_repeating_field_group-0.2.0.tar.gz",
    "platform": null,
    "description": "# st-repeating-field-group\r\n\r\nA Streamlit plugin for creating dynamic, repeating field groups with add/remove functionality and conditional field display.\r\n\r\n## Installation\r\n\r\nInstall the package using pip:\r\n\r\n```bash\r\npip install st-repeating-field-group\r\n```\r\n\r\n## Features\r\n\r\n- Create repeating groups of form fields\r\n- Dynamically add and remove field groups\r\n- Support for various field types: text, number, date, checkbox, toggle, slider, range slider, and dropdown\r\n- Conditional field display based on other field values\r\n- Customizable default values\r\n\r\n## Usage\r\n\r\n### Basic Usage\r\n\r\nHere's a simple example of how to use the `generate_repeating_field_group` function:\r\n\r\n```python\r\nimport streamlit as st\r\nfrom st_repeating_field_group import generate_repeating_field_group\r\n\r\nkeys = {\r\n    \"name\": {\"type\": str, \"default\": \"\"},\r\n    \"age\": {\"type\": int, \"default\": 0},\r\n    \"is_student\": {\"type\": \"checkbox\", \"default\": False}\r\n}\r\n\r\ngroup_id = \"example_group\"\r\ndefault_values = [\r\n    {\"name\": \"John Doe\", \"age\": 30, \"is_student\": False},\r\n    {\"name\": \"Jane Smith\", \"age\": 25, \"is_student\": True}\r\n]\r\n\r\nrows = generate_repeating_field_group(keys, group_id, default_values)\r\n\r\nst.write(rows)\r\n```\r\n\r\n### Advanced Usage with Conditional Fields and Range Slider\r\n\r\nYou can use the `only_show_if` parameter to conditionally display fields based on the values of other fields in the same group. Here's an example that also includes a range slider:\r\n\r\n```python\r\nimport streamlit as st\r\nfrom st_repeating_field_group import generate_repeating_field_group\r\n\r\nkeys = {\r\n    \"name\": {\"type\": str, \"default\": \"\"},\r\n    \"age\": {\"type\": int, \"default\": 0},\r\n    \"is_student\": {\"type\": \"checkbox\", \"default\": False},\r\n    \"school_name\": {\r\n        \"type\": str,\r\n        \"default\": \"\",\r\n        \"only_show_if\": {\r\n            \"kwargs\": {\"is_student\": \"is_student\"},\r\n            \"func\": lambda is_student: is_student\r\n        }\r\n    },\r\n    \"job_title\": {\r\n        \"type\": str,\r\n        \"default\": \"\",\r\n        \"only_show_if\": {\r\n            \"kwargs\": {\"is_student\": \"is_student\"},\r\n            \"func\": lambda is_student: not is_student\r\n        }\r\n    },\r\n    \"salary_range\": {\r\n        \"type\": \"range_slider\",\r\n        \"default\": (30000, 80000),\r\n        \"min\": 0,\r\n        \"max\": 200000,\r\n        \"step\": 1000,\r\n        \"only_show_if\": {\r\n            \"kwargs\": {\"is_student\": \"is_student\"},\r\n            \"func\": lambda is_student: not is_student\r\n        }\r\n    }\r\n}\r\n\r\ngroup_id = \"advanced_example_group\"\r\ndefault_values = [\r\n    {\"name\": \"John Doe\", \"age\": 30, \"is_student\": False, \"job_title\": \"Engineer\", \"salary_range\": (50000, 100000)},\r\n    {\"name\": \"Jane Smith\", \"age\": 25, \"is_student\": True, \"school_name\": \"University XYZ\"}\r\n]\r\n\r\nrows = generate_repeating_field_group(keys, group_id, default_values)\r\n\r\nst.write(rows)\r\n```\r\n\r\nIn this example, the \"school_name\" field will only be displayed if \"is_student\" is checked, while the \"job_title\" and \"salary_range\" fields will only be displayed if \"is_student\" is not checked.\r\n\r\n### Supported Field Types\r\n\r\nThe `generate_repeating_field_group` function supports the following field types:\r\n\r\n- `str` or `\"str\"`: Text input\r\n- `int` or `\"int\"`: Integer input\r\n- `float` or `\"float\"`: Float input\r\n- `\"choice\"`: Dropdown selection\r\n- `\"date\"`: Date input\r\n- `\"toggle_switch\"`: Toggle switch\r\n- `\"checkbox\"`: Checkbox\r\n- `\"slider\"`: Slider input\r\n- `\"range_slider\"`: Range slider input\r\n\r\n### Parameters\r\n\r\n- `keys` (dict): A dictionary defining the fields and their properties.\r\n- `group_id` (str): A unique identifier for the field group.\r\n- `default_values` (list, optional): Default values for the fields.\r\n\r\n#### Field Properties\r\n\r\nEach field in the `keys` dictionary can have the following properties:\r\n\r\n- `type`: The data type or input type of the field (required).\r\n- `default`: The default value for the field (required).\r\n- `choices`: A list of options for dropdown fields (required for \"choice\" type).\r\n- `min`: Minimum value for numeric or slider fields (optional).\r\n- `max`: Maximum value for numeric or slider fields (optional).\r\n- `step`: Step size for numeric or slider fields (optional).\r\n- `only_show_if`: A dictionary containing conditional display logic (optional).\r\n\r\n#### Using `only_show_if`\r\n\r\nThe `only_show_if` property allows you to conditionally display fields based on the values of other fields in the same group. It has two sub-properties:\r\n\r\n- `kwargs`: A dictionary mapping parameter names to field names in the current group.\r\n- `func`: A function that takes the mapped field values as arguments and returns a boolean indicating whether the field should be displayed.\r\n\r\nExample:\r\n\r\n```python\r\n\"school_name\": {\r\n    \"type\": str,\r\n    \"default\": \"\",\r\n    \"only_show_if\": {\r\n        \"kwargs\": {\"is_student\": \"is_student\"},\r\n        \"func\": lambda is_student: is_student\r\n    }\r\n}\r\n```\r\n\r\nIn this example, the \"school_name\" field will only be displayed if the \"is_student\" checkbox is checked.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Streamlit plugin for creating repeating field groups",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/joey12725/st-repeating-field-group"
    },
    "split_keywords": [
        "streamlit",
        "plugin",
        "repeating",
        "field",
        "group"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "34125010148d463ea713f54fa9f0f4d23835769913dc6a877857cc9418ab4045",
                "md5": "3093fbe2cd9732223a3d0a74c3da9219",
                "sha256": "d21256debde33c996e449ed836372dcd41669d26083a5567b825d498574dc5f4"
            },
            "downloads": -1,
            "filename": "st_repeating_field_group-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3093fbe2cd9732223a3d0a74c3da9219",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5788,
            "upload_time": "2024-09-03T20:40:13",
            "upload_time_iso_8601": "2024-09-03T20:40:13.990365Z",
            "url": "https://files.pythonhosted.org/packages/34/12/5010148d463ea713f54fa9f0f4d23835769913dc6a877857cc9418ab4045/st_repeating_field_group-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7deab5819523c238db8adf2118f0502235178a2f54f676620f28b18ad639904e",
                "md5": "e656b79f1ce22af7b65e8185d2132dd1",
                "sha256": "101b6affeb1f65a0c252b5e6bf73794b420ba84176da0e25d87ab8b960b16d2c"
            },
            "downloads": -1,
            "filename": "st_repeating_field_group-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e656b79f1ce22af7b65e8185d2132dd1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5401,
            "upload_time": "2024-09-03T20:40:15",
            "upload_time_iso_8601": "2024-09-03T20:40:15.341807Z",
            "url": "https://files.pythonhosted.org/packages/7d/ea/b5819523c238db8adf2118f0502235178a2f54f676620f28b18ad639904e/st_repeating_field_group-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-03 20:40:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "joey12725",
    "github_project": "st-repeating-field-group",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "st-repeating-field-group"
}
        
Elapsed time: 0.34955s