|
import streamlit as st |
|
from util import getYamlConfig |
|
|
|
def page(): |
|
st.subheader("Définissez vos paramètres") |
|
|
|
|
|
config = getYamlConfig() |
|
|
|
|
|
if 'parts' in config['variables']: |
|
|
|
parts = config["variables"]["parts"] |
|
parts_sorted = sorted(parts, key=lambda part: part.get('number', float('inf'))) |
|
|
|
|
|
tabs = st.tabs([part['name'] for part in parts_sorted]) |
|
for part, tab in zip(parts_sorted, tabs): |
|
with tab: |
|
for field in part['fields']: |
|
display_field(field) |
|
else: |
|
|
|
for field in st.session_state.data_dict: |
|
display_field(field) |
|
|
|
|
|
def display_field(field): |
|
"""Helper function to create the correct input based on field 'nature'.""" |
|
if field['nature'] == 'radio': |
|
value = st.radio(field['label'], field['options'], key=field['key']) |
|
field['value'] = value |
|
elif field['nature'] == 'selectbox': |
|
value = st.selectbox(field['label'], field['options'], key=field['key']) |
|
field['value'] = value |
|
elif field['nature'] == 'multiselect': |
|
value = st.multiselect(field['label'], field['options'], key=field['key']) |
|
field['value'] = value |
|
elif field['nature'] == 'date': |
|
value = st.date_input(field['label'], key=field['key']) |
|
field['value'] = value |
|
elif field['nature'] == 'numeric': |
|
value = st.number_input(field['label'], key=field['key']) |
|
field['value'] = value |
|
elif field['nature'] == 'text_area': |
|
value = st.text_area(field['label'], value=field['value'] if 'value' in field else "", key=field['key']) |
|
field['value'] = value |
|
else: |
|
value = st.text_input(label=field['label'], value=field['value'] if 'value' in field else "") |
|
field['value'] = value |
|
|
|
page() |
|
|