Streamlit horizontal scroll table

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)

Hi, are you using st.dataframe - Streamlit Docs ?
Because there is already the scroll in it. Otherwise, i don’t see what you mean, if you got a screenshoot/exemple of what you want to display it will help.

Thank you for your response. The element you mentioned has horizontal scrolling, but the type of columns that can be used there do not allow creating cells with buttons to perform actions on the data of each row.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.