Skip to content

Commit

Permalink
feat: flexible table height
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhou committed Apr 5, 2024
1 parent 0156a3a commit 6171475
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions code/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ def app():
cols = st.columns([1, 1.2])
with cols[0]:
st.markdown('## 🌳🪴 Foraging sessions from Bonsai 🌳🪴')
st.markdown('##### (still using a temporary workaround until AIND behavior metadata and pipeline are set up)')

with st.sidebar:

Expand Down Expand Up @@ -624,14 +623,18 @@ def app():
# with col1:
# -- 1. unit dataframe --

cols = st.columns([2, 2, 2])
cols[0].markdown(f'### Filter the sessions on the sidebar ({len(st.session_state.df_session_filtered)} filtered)')
# if cols[1].button('Press this and then Ctrl + R to reload from S3'):
# st.rerun()
if cols[1].button('Reload data '):
st.cache_data.clear()
init()
st.rerun()
cols = st.columns([2, 1, 4, 1])
cols[0].markdown(f'### Filter the sessions on the sidebar\n'
f'##### {len(st.session_state.df_session_filtered)} sessions, '
f'{len(st.session_state.df_session_filtered.h2o.unique())} mice filtered')
with cols[1]:
st.markdown('# ')
if st.button(' Reload data ', type='primary'):
st.cache_data.clear()
init()
st.rerun()

table_height = cols[3].slider('Table height', 100, 2000, 400, 50, key='table_height')

# aggrid_outputs = aggrid_interactive_table_units(df=df['ephys_units'])
# st.session_state.df_session_filtered = aggrid_outputs['data']
Expand All @@ -643,7 +646,7 @@ def app():
st.markdown('## No filtered results!')
return

aggrid_outputs = aggrid_interactive_table_session(df=st.session_state.df_session_filtered)
aggrid_outputs = aggrid_interactive_table_session(df=st.session_state.df_session_filtered, table_height=table_height)

if len(aggrid_outputs['selected_rows']) and not set(pd.DataFrame(aggrid_outputs['selected_rows']
).set_index(['h2o', 'session']).index
Expand Down
4 changes: 2 additions & 2 deletions code/util/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"padding": "4px !important"},
}

def aggrid_interactive_table_session(df: pd.DataFrame):
def aggrid_interactive_table_session(df: pd.DataFrame, table_height: int = 400):
"""Creates an st-aggrid interactive table based on a dataframe.
Args:
Expand Down Expand Up @@ -92,7 +92,7 @@ def aggrid_interactive_table_session(df: pd.DataFrame):
theme="balham",
update_mode=GridUpdateMode.SELECTION_CHANGED,
allow_unsafe_jscode=True,
height=400,
height=table_height,
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
custom_css=custom_css,
)
Expand Down

0 comments on commit 6171475

Please sign in to comment.