[英]How to set a max column length for streamlit-aggrid
如果我有一個非常長的列條目占用了大部分表格(如下所示),我該如何設置表格選項以使其被截斷?
import streamlit as st
from st_aggrid import AgGrid
import pandas as pd
df = pd.DataFrame({'some short column': ['a', 'b', 'c'],
'some long column': ['all column and no spacing makes coder a dull boy '
'all column and no spacing makes coder a dull boy '
'all column and no spacing makes coder a dull boy '
'all column and no spacing makes coder a dull boy '
'all column and no spacing makes coder a dull boy '
'all column and no spacing makes coder a dull boy '
'all column and no spacing makes coder a dull boy '
'all column and no spacing makes coder a dull boy ', 'two', 'three'],
'some other column': ['one', 'two', 'three'],
'some other column 2': ['one', 'two', 'three']})
AgGrid(df)
編輯:
AgGrid(df, fit_columns_on_grid_load=True)
使用 fit_columns_on_grid_load 參數,默認為 False。
AgGrid(df, fit_columns_on_grid_load=True)
感謝這個組合! 不過,我不得不在單獨的配置行中添加fit_columns_on_grid
,因此:
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_default_column(min_column_width=150)
interactive_table = AgGrid(df, gridOptions=gb.build(), fit_columns_on_grid_load=True)
結合@ferdy的回答。 如果我使用:
gb = GridOptionsBuilder.from_dataframe(df, min_column_width=30)
AgGrid(df, gridOptions=gb.build(), fit_columns_on_grid_load=True)
然后它可以安全地工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.