Hey everyone - I’m having some weird behavior with the Dash Datatable with the following code and was wondering whether anyone else who runs this also has the same bug. I want the table to be scrollable horizontally, but it seems to have a really weird behavior when you scroll because it keeps trying to pull the whole thing back to the original position and I’m also not able to set the column width for the “pad” column to be any kind of small pixel width. Any help that you all might have would be appreciated. Thanks!
import dash
from dash import html
import dash_table
import pandas as pd
from collections import OrderedDict
data_election = OrderedDict(
[
(
"Date",
[
"July 12th, 2013 - July 25th, 2013",
"July 12th, 2013 - August 25th, 2013",
"July 12th, 2014 - August 25th, 2014",
],
),
(
"Election Polling Organization",
["The New York Times", "Pew Research", "The Washington Post"],
),
("Rep", [1, -20, 3.512]),
("Dem", [10, 20, 30]),
("Ind", [2, 10924, 3912]),
("pad", [None,None, None]),
(
"Region",
[
"Northern New York State to the Southern Appalachian Mountains",
"Canada",
"Southern Vermont",
],
),
]
)
df = pd.DataFrame(data_election)
app = dash.Dash(__name__)
app.layout = html.Div(
dash_table.DataTable(
data=df.to_dict('records'),
columns=[
{"id": "Date", "name": ["INFO", "Date"]},
# {"id": "Election Polling Organization", "name": ["INFO", "Election Polling Organization"]},
{"id": "Rep", "name": ["Party1", "Rep"]},
{"id": "Dem", "name": ["Party1", "Dem"]},
{"id": "pad", "name": ["", ""]},
{"id": "Ind", "name": ["Party3", "Ind"]},
{"id": "Region", "name": ["INFO", "Region"]},
],
# columns=[{'id': c, 'name': ["test_", c]} for c in df.columns],
merge_duplicate_headers=True,
fixed_columns={ 'headers': True, 'data': 1 },
style_table={'minWidth': '100%'},
style_cell={
# all three widths are needed
'minWidth': '100px', 'width': '100px', 'maxWidth': '100px',
'overflow': 'hidden',
'textOverflow': 'ellipsis',
},
style_cell_conditional=[
{'if': {'column_id': ['Rep', 'Dem', 'Ind']},
'minWidth': '50px', 'width': '50px', 'maxWidth': '50px'},
{'if': {'column_id': ['Region']},
'minWidth': '75px', 'width': '75px', 'maxWidth': '75px'},
{'if': {'column_id': ['pad']},
'minWidth': '2px', 'width': '2px', 'maxWidth': '2px'},
]
),
style={'width': '400px', 'margin-right': 'auto'},
)
if __name__ == '__main__':
app.run_server(debug=True)