I have a table with many elements, I have been looking for a way to create a horizontal scroll so that all the elements can be displayed but I have not been successful, does anyone have an idea of how I can do it?
I am creating the table this way because I need to add some actions that I cannot add with st.table or dataf.
def create_streamlit_table(df):
col_widths = {col: len(col) * 10 for col in df.columns}
col_widths['prompt_variant'] = 300
columns = st.columns([col_widths[col] for col in df.columns])
for col, field_name in zip(columns, df.columns):
col.write(field_name)
for _, row in df.iterrows():
cols = st.columns([col_widths[col] for col in df.columns])
for i, col_name in enumerate(df.columns):
cell_content = row[col_name]
if col_name == 'prompt_variant' or len(str(cell_content)) > 100:
cols[i].markdown(f"<div style='height: 150px; overflow-y: auto;'>{cell_content}</div>", unsafe_allow_html=True)
else:
cols[i].write(cell_content)