Thank you Marc-Andre
I worked on creating a code snippet to illustrate the problem I see without any dependencies:
version 1 works I am updating only the data
version 2 I am updating the data and the columns and the table is empty as no columns are showing:
for version 2 please do comment back in the 2nd Output and return of the callback function
Thanks
This is the code :
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table
from dash_table.Format import Format, Scheme, Sign, Symbol
import dash_table.FormatTemplate as FormatTemplate
from dash.dependencies import Input, Output, State
import pandas as pd
import numpy as np
app = dash.Dash(__name__)
app.title = 'Futures'
app.layout = html.Div(style={'marginLeft':25,'marginRight':25},
children=[
html.Div(className='row',children=[
html.Div(className='four columns',
children =[
]),
html.Div(className='four columns',
children =[
html.H6('Order Book'),
html.Hr(style={'border-color':'#cb1828'}),
html.Div(children=[dash_table.DataTable(id='fut-order-table',
columns=[{'id':'from_mid','name':'From Mid','type':'numeric','format':FormatTemplate.percentage(4)},
{'id':'price','name':'Price'},{'id':'size','name':'Size'},{'id':'cum_size','name': 'Size Total'},
{'id':'size_$','name':'Size $','type':'numeric','format':FormatTemplate.money(0)},
{'id':'cum_size_$','name':'Size Total $','type':'numeric','format':FormatTemplate.money(0)},
{'id':'average_fill','name':'Averge Fill'},{'id':'exc','name':'Exchange'},
{'id':'side','name':'side','hidden':True}],
style_table={'border': 'thin lightgrey solid'},
style_header={'backgroundColor':'lightgrey','fontWeight':'bold'},
style_cell={'textAlign':'center','width':'12%'},
style_data_conditional=[{
'if' : {'filter': 'side eq "bid"' },
'color':'blue'
}
]+[
{
'if' : {'filter': 'side eq "ask"' },
'color':'rgb(203,24,40)'
}]+[
{ 'if': {'row_index':'odd'},
'backgroundColor':'rgb(242,242,242)'}
]+[
{'if':{'column_id':'price'},
'fontWeight':'bold',
'border': 'thin lightgrey solid'}
]+[{'if':{'column_id':'from_mid'},
'fontWeight':'bold'}
],
style_as_list_view=True
)
]),
html.Hr(style={'border-color':'#cb1828'}),
html.H6('Liquidity Metrics'),
html.P(id='fut-liquidity-table'),
html.H6('Slippage %'),
html.P(id='fut-depth-table'),
html.H6('Coin Stats'),
html.P(id='fut-stat-table')
]),
html.Div(className='four columns',
children =[html.H6('Order Management'),
html.Hr(style={'border-color':'#cb1828'}),
html.H6('Orders'),
html.Hr(style={'border-color':'#cb1828'}),
html.Div(children = [
html.Button(id='update_click',children =['Refresh'],
style = {'margin-top' :'10px','background-color':'#cb1828','color':'#FFF'})]),
])
]),
])
@app.callback(
Output('fut-order-table','data'),#, Output('fut-order-table','columns')],
[Input('update_click','n_clicks')],)
def update_page(n_clicks):
step = .0001
# order table columns
r = int(np.ceil(-np.log(step)/np.log(10)))-2
columns_ob=[{'id':'from_mid','name':'From Mid','type':'numeric','format':FormatTemplate.percentage(r)},
{'id':'price','name':'Price'},{'id':'size','name':'Size'},{'id':'cum_size','name': 'Size Total'},
{'id':'size_$','name':'Size $','type':'numeric','format':FormatTemplate.money(0)},
{'id':'cum_size_$','name':'Size Total $','type':'numeric','format':FormatTemplate.money(0)},
{'id':'average_fill','name':'Averge Fill'},{'id':'exc','name':'Ex'},
{'id':'side','name':'side','hidden':True}],
# order table data
df = pd.DataFrame(np.random.randn(24,9),columns=['from_mid','price','size','cum_size','size_$','cum_size_$','average_fill','exc','side'])
data_ob = df.to_dict('rows')
return (data_ob)#,columns_ob)
if __name__ == '__main__' :
app.run_server(port=8055,debug=True)