Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict page width #153

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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