Streamlit-Aggrid

Hi,

Is there a way to hide column headers with streamlit-aggrid.

Thanks

ob = GridOptionsBuilder.from_dataframe(df)
ob.configure_column("Details", hide=True)

See this post too.

Hi,

Thank you for your response.

I tried the following solution but it did not work. I still see the column headers in the grid.

Thanks
Prerna

Could you provide a minimal and simplified version of the code where you are encountering issues?

Hi,

Please see below code. I am creating a grid to display the totals but I do not want the columns in the “Delivered_Total_df” to be displayed. I only want the values but it still shows the header

delivered_totals_df = grid_df.loc[grid_df[‘order_created_year’] == ‘total:’]

delivered_totals_df=delivered_totals_df[[‘eto_delivered_count’,‘gross_ch_delivered_revenue’,‘gross_ch_delivered_cost’, ‘gross_ch_delivered_margin’,‘avg_order_life_span_in_days’]].copy()

delivered_totals_df = delivered_totals_df.iloc[[-1]]

delivered_totals_df.insert(0, " ", “Total”)

options1 = GridOptionsBuilder.from_dataframe(delivered_totals_df)

options1.configure_column(“Details”, hide=True)

options1.configure_side_bar()

options1.configure_selection(“single”)

options1.configure_column(“gross_ch_delivered_revenue”, header_name=None, cellStyle={‘text-align’: “center”})

options1.configure_column(“gross_ch_delivered_cost”, header_name=None, cellStyle={‘text-align’: “center”})

options1.configure_column(“eto_delivered_count”, header_name=None, cellStyle={‘text-align’: “center”})

options1.configure_column(“gross_ch_delivered_margin”, header_name=None, cellStyle={‘text-align’: “center”})

options1.configure_column(“avg_order_life_span_in_days”, header_name=None, cellStyle={‘text-align’: “center”})

AgGrid(delivered_totals_df, height=min(MIN_HEIGHT+len(delivered_totals_df)*ROW_HEIGHT, MAX_HEIGHT), fit_columns_on_grid_load = True,gridOptions=options1.build(), allow_unsafe_jscode=True,)

Thanks

Prerna

Sorry the solution I give is wrong. It will hide the entire column. Let me think of other ways.

Have a look at this example, it will sort of hide the column header Country.

from st_aggrid import GridOptionsBuilder, AgGrid
import pandas as pd


df = pd.DataFrame({'Country': ['Japan', 'Norway'],
                    'Capital': ['Tokyo', 'Oslo']})

gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_column('Country', header_name='')
    
AgGrid(df, gb.build())

Image

image

Thank You so much. That worked.

Prerna

Hi @prerna108

You can hide all your aggrid headers like this:

import streamlit as st
from st_aggrid import GridOptionsBuilder, AgGrid
import pandas as pd

df = pd.DataFrame({'Country': ['Japan', 'Norway'], 'Capital': ['Tokyo', 'Oslo']})
gb = GridOptionsBuilder.from_dataframe(df)
gridOptions = gb.build()
gridOptions["headerHeight"]=0

AgGrid(df, gridOptions)

Cheers

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