Skip to content

Commit

Permalink
Merge pull request #153 from agoenergy/centered_wide_layout
Browse files Browse the repository at this point in the history
Restrict page width
  • Loading branch information
markushal authored Nov 30, 2023
2 parents 3a1f362 + 8c4ab37 commit 669fd09
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
71 changes: 35 additions & 36 deletions app/layout_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,43 @@ def display_costs(
"""Display costs as table and bar chart."""
key_suffix = key_suffix.lower().replace(" ", "_")
st.subheader(titlestring)
c1, c2 = st.columns([1, 5])
with c1:
# filter data:
df_res = df_costs.copy()

# select filter:
show_which_data = st.radio(
"Select elements to display:",
["All", "Manual select"],
index=0,
key=f"show_which_data_{key}_{key_suffix}",
)

# apply filter:
if show_which_data == "Manual select":
ind_select = st.multiselect(
"Select regions:",
df_res.index.values,
default=df_res.index.values,
key=f"select_data_{key}_{key_suffix}",
)
df_res = df_res.loc[ind_select]

# sort:
sort_ascending = st.toggle(
"Sort by total costs?",
value=True,
key=f"sort_data_{key}_{key_suffix}",
)
if sort_ascending:
df_res = df_res.sort_values(["Total"], ascending=True)
with c2:
# create graph:
fig = create_bar_chart_costs(
df_res,
current_selection=st.session_state[key],
# filter data:
df_res = df_costs.copy()

# select filter:
show_which_data = st.radio(
"Select elements to display:",
["All", "Manual select"],
index=0,
horizontal=True,
key=f"show_which_data_{key}_{key_suffix}",
)

# apply filter:
if show_which_data == "Manual select":
ind_select = st.multiselect(
"Select regions:",
df_res.index.values,
default=df_res.index.values,
key=f"select_data_{key}_{key_suffix}",
)
st.plotly_chart(fig, use_container_width=True)
df_res = df_res.loc[ind_select]

# sort:
sort_ascending = st.toggle(
"Sort by total costs?",
value=True,
key=f"sort_data_{key}_{key_suffix}",
)
if sort_ascending:
df_res = df_res.sort_values(["Total"], ascending=True)
# create graph:
fig = create_bar_chart_costs(
df_res,
current_selection=st.session_state[key],
)
st.plotly_chart(fig, use_container_width=True)

with st.expander("**Data**"):
column_config = config_number_columns(
Expand Down
9 changes: 8 additions & 1 deletion ptxboa_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@
if "edit_input_data" not in st.session_state:
st.session_state["edit_input_data"] = False

st.set_page_config(layout="wide")
# https://discuss.streamlit.io/t/can-not-set-page-width-in-streamlit-1-5-0/21522/5
css = """
<style>
section.main > div {max-width:80rem}
</style>
"""
st.markdown(css, unsafe_allow_html=True)

api = st.cache_resource(PtxboaAPI)()
st.title("PtX Business Opportunity Analyzer :red[draft version, please do not quote!]")

Expand Down

0 comments on commit 669fd09

Please sign in to comment.