Datatable hiding a series of columns

reading in columns

columns=[{"name": i, "id": i} for i in df_today.columns],

gets the columns

prev, day _only, hv2010 , hv105 , hvrelpct , num_symbols, up_count

I want to HIDE

hv2010 , hv105 , hvrelpct

BUT I really don’t understand the documentation.

1 Like


You could try with following code:

columns=[{"name": i, "id": i} for i in df_today.columns.drop(['hv2010', 'hv105', 'hvrelpct'])]

which simply drops the columns ‘hv2010’, ‘hv105’ and ‘hvrelpct’ from the series, which is used as an input for the datatable column creation.


Hi @toivaan thank you for taking an interest. I don’t want to do that as Dash datatable has a parameter which hides the columns. IE

   columns=[{'name': 'A', 'id': 'A'},
            {'name': 'B', 'id': 'B', 'hidden': True}],

BUT ( and this is my stupidity) I can’t get my head around how to incorporate the approach above into my code.

columns=[{"name": i, "id": i} for i in df_today.columns],

I pretty sure it’s easy but I CANNOT wrap my head around it.
I thank you for your suggestion BUT I suspect I will break something later on if I start to mess with the dataframe


Got it! And being a Dash-newbie myself, I actually found out that there already is a much more sophisticated method for hiding certain columns:

hidden_columns=['foo', 'bar']

So your code would be:

columns=[{"name": i, "id": i} for i in df_today.columns],
hidden_columns=['hv2010', 'hv105', 'hvrelpct'],


1 Like

WOW that was embarrassing :wink:

I seem to have lost the ability to read. I’m not too sure why I missed that CLEARLY documented feature but stupidity certainly played a significant role. Thank you so much for taking the time and it worked like a champ.

I would like to reciprocate with a little advice from my experiences as a Dash noob. I find Adam’s approach is WONDERFULLY helpful. Well documented, presentation is captivating AND he covers EXACTLY what I needed to know to just get a simple app up an running. Here is the link ( below) and thanks again Toivaan

1 Like