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:
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:
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:
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:
stror"str": Text inputintor"int": Integer inputfloator"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:
"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 file for details.
Metadata
Release files for st-repeating-field-group 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| st_repeating_field_group-0.2.0.tar.gz | 5.4 kB | Without provenance | Details for st_repeating_field_group-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| st_repeating_field_group-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for st_repeating_field_group-0.2.0-py3-none-any.whl |
Total release size: 11.2 kB
Release files / st_repeating_field_group-0.2.0.tar.gz
| Download URL | st_repeating_field_group-0.2.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
101b6affeb1f65a0c252b5e6bf73794b420ba84176da0e25d87ab8b960b16d2c
|
|
BLAKE2b-256 checksum How to use checksums |
7deab5819523c238db8adf2118f0502235178a2f54f676620f28b18ad639904e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / st_repeating_field_group-0.2.0-py3-none-any.whl
| Download URL | st_repeating_field_group-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d21256debde33c996e449ed836372dcd41669d26083a5567b825d498574dc5f4
|
|
BLAKE2b-256 checksum How to use checksums |
34125010148d463ea713f54fa9f0f4d23835769913dc6a877857cc9418ab4045
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Security for st-repeating-field-group 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.