I am using Dash to create a multi-page dashboard and its going well. On one of the pages, I have a Dash datatable that is simply a One-sheet Excel Workbook. Its uploading, fine and its all working. I have it formatted in Excel the way I want with some rows as $ and some as %. But once its comes into the databale, the number format goes away is is simply the numbers with about 10 decimal points. I even tried opening the Excel file and then rewriting it with pd.ExcelWriter. The formatting it correct in the Excel file, just not when it goes into the Dash databale. So fustrating.
Here are the relevant parts of the code:
df_income_statement = pd.read_excel(‘Income_Statement.xlsx’)
def tab1_content():
return html.Div([
html.Div(
dash_table.DataTable(
id=‘table’,
columns=[{“name”: i, “id”: i} for i in df_income_statement.columns],
data=df_income_statement.to_dict(‘records’),
fixed_columns={‘headers’: True, ‘data’: 1}, # puts in a vertical scroll bar if necessary
fixed_rows={‘headers’: True, ‘data’: 0}, # puts in a horizontal scroll bar if necessary
# style_cell={‘format’: “{:.2f}%”},
style_cell={‘format’: ‘{:.2f}%}’, ‘fontFamily’: ‘sans-serif’, ‘fontSize’: ‘12px’, ‘color’: ‘white’,
‘border’: ‘0px’, ‘background’: ‘black’, ‘foreground’: ‘white’},
# this takes the cell boarders out so it does not look like a spreadsheet (border)
style_table={‘minWidth’: ‘100%’, ‘height’: ‘400px’}, #overflow:scroll #‘overflow’: ‘inherit’ #hover’: ‘{background-color:red;}’
style_cell_conditional=[
{
‘if’: {‘column_id’: ‘$ in millions’},
‘textAlign’: ‘left’,
‘color’: ‘red’,
‘fontWeight’: ‘bold’},
{
‘if’: {‘column_id’: “C”},
‘textAlign’: ‘center’,
‘color’: ‘yellow’},
{
‘if’: {‘column_id’: “Growth”},
‘textAlign’: ‘center’,
‘color’: ‘red’},
],
style_header_conditional=[
{
'if': {'column_id': '$ in millions'},
'textAlign': 'left'
},
],
style_header={
'backgroundColor': 'black',
'color': 'white',
'fontWeight': 'bold',
'borderBottom': '2px solid white',
'text-align': 'center'
}
)
)
])
Any help would be mush appreciated.
Rick