Skip to content

Commit

Permalink
improve number format in data tables (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
markushal committed Nov 8, 2023
1 parent 785964e commit 2b40b0b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/ptxboa_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def content_market_scanning(

# show data in tabular form:
st.markdown("**Data:**")
st.dataframe(df_plot, use_container_width=True)
st.dataframe(df_plot.style.format(precision=2), use_container_width=True)


def remove_subregions(api: PtxboaAPI, df: pd.DataFrame, settings: dict):
Expand Down Expand Up @@ -554,7 +554,7 @@ def content_costs_by_region(
create_bar_chart_costs(df_res)

st.write("**Data:**")
st.dataframe(df_res, use_container_width=True)
st.dataframe(df_res.style.format(precision=2), use_container_width=True)


def content_deep_dive_countries(
Expand Down Expand Up @@ -765,18 +765,29 @@ def display_and_edit_data_table(
df = input_data.loc[ind1 & ind2 & ind3]
df_tab = df.pivot_table(index=index, columns=columns, values=values, aggfunc="sum")

# if editing is enabled, store modifications in session_state:
if st.session_state["edit_input_data"]:
disabled = [index]
key = f"edit_input_data_{parameter_code}"
else:
disabled = True
key = None

# configure columns for display:
column_config = {}
for c in df_tab.columns:
column_config[c] = st.column_config.NumberColumn(
format="%.2f",
)

# display data:
st.data_editor(
df_tab,
df_tab.style.format(precision=2),
use_container_width=True,
key=key,
num_rows="fixed",
disabled=disabled,
column_config=column_config,
)

# store changes in session_state:
Expand Down

0 comments on commit 2b40b0b

Please sign in to comment.