Skip to content

Commit e62b7f0

Browse files
author
Adriano Sanges
committed
Add column display options in main.py
- Introduced a checkbox to toggle the visibility of all columns in the data table. - Defined a mapping for default column names to improve readability. - Updated the data display logic to conditionally show either all columns or a subset with renamed headers based on user selection.
1 parent 096a44e commit e62b7f0

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

main.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def main():
2626
st.caption("Dati del 2024")
2727

2828

29+
show_all_columns = st.checkbox("Mostra tutte le colonne", value=False)
30+
31+
default_columns = {
32+
"Comune_descrizione" : "Comune",
33+
"Descr_Tipologia" : "Tipologia",
34+
"Zona_Descr" : "Zona",
35+
"Compr_min" : "Prezzo acquisto minimo al mq (€)",
36+
"Compr_max" : "Prezzo acquisto massimo al mq (€)",
37+
"Loc_min" : "Prezzo locazione minimo al mq (€)",
38+
"Loc_max" : "Prezzo locazione massimo al mq (€)"
39+
}
2940

3041
regioni_dataset = get_regioni(conn)["Regione"]
3142
selected_regione =st.sidebar.selectbox("Seleziona la regione", regioni_dataset)
@@ -40,8 +51,15 @@ def main():
4051

4152
if(selected_tipologia != None):
4253
result = conn.execute(f"SELECT * FROM joined_data WHERE Regione = '{selected_regione}' and Comune_descrizione = '{selected_comune}' and Descr_Tipologia = '{selected_tipologia}'").df()
43-
st.table(result)
44-
54+
readable_columns = {**default_columns, **{col: col for col in result.columns if col not in default_columns}}
55+
56+
if(show_all_columns):
57+
st.dataframe(result)
58+
59+
else:
60+
61+
display_df = result[list(default_columns.keys())].rename(columns=default_columns)
62+
st.dataframe(display_df)
4563

4664
except Exception as e:
4765
print(f"An error occurred: {e}")

0 commit comments

Comments
 (0)