app.layout = html.Div([
html.Hr(),
html.H3(id = 'H1', children = ['Flow'], style = {'textAlign':'center', 'color':'rgb(0, 128, 0)','fontSize':'25px'}),
dbc.Row([
# default date is last business day date
dbc.Col([
html.Label(id = 'Date', children = ' Date: ',style = {'color':'rgb(0, 128, 0)','marginLeft':10}),
dcc.Input(id ='datevalue',
value = datetime.strftime(yesterday, '%Y%m%d'),
style = {'textAlign':'center', 'marginLeft':'10px'},
type='text'
),
],width = 2),
# notional default is 500,000 thus only rows with notional>500,000 show up by default
dbc.Col([
html.Label(id = 'Ticker', children = ' Ticker: ',style = {'color':'rgb(0, 128, 0)'}),
dcc.Input(id ='ticker',
value = 'ECN',
style = {'textAlign':'center','marginLeft':'5px'},
type='text'
),
],width = {'size':3,'offset':2}),
# allows user to fetch the first or last batch of stock prices
dbc.Col([
html.Label(id = 'Currency', children = ' Currency: ',style = {'color':'rgb(0, 128, 0)','marginLeft':10}),
dcc.Input(id ='currency',
value='CAD',
style = {'textAlign':'center','marginLeft':'5px'},
type = 'text',
),
],width = 2),
]),
# lets user update input fields themselves to update output, includes a loading button
dbc.Spinner(children=[html.Button('Update', id='interval-component',style = {'marginLeft':'10px'}),
html.Div(id='page-3-content')
], color = 'rgb(0,128,0)'),
])
# callback takes in 4 variables including one input variable and 3 state variables - so that output only updates once user presses 'Update'
@callback(
Output('page-3-content','children'),
[State('datevalue','value'),
State('ticker','value'),
State('currency','value'),
Input('interval-component', 'n_clicks')
])
# datatable is using the dataframe from the query
def update_output(dateval,symbol,curr,n):
table = pd.pivot_table(df, values = 'Volume',index = ['Desk'],columns = ['TransactionType'], aggfunc=np.sum, fill_value=0, margins=True, margins_name='Grand Total')
tableoutput = dash_table.DataTable(id='dataframe', columns=[{'id':c, 'name':c, 'type':'numeric', 'format':Format(group=True, groups=[3])} for c in df.columns],
data=df.to_dict('records'),editable=False,filter_action="native",sort_action="native",selected_rows=[],sort_mode="multi",page_current= 0,page_action="native",
css=[{'selector': '.dash-spreadsheet tr', 'rule': 'height: 10px;'}], fixed_rows={'headers': True},
style_cell_conditional=[
{
'if': {'column_id': c},
'textAlign': 'center','width': '8.33%'
} for c in df.columns
],
style_data={
'color': 'black',
'backgroundColor': 'white'
},
style_header={
'backgroundColor': 'rgb(0, 128, 0)',
'color': 'white',
'fontWeight': 'bold'
}
)
return tableoutput, table
Hi,
I have this code where I have not included the sql pull. My df is correct and my table does exist if I print it but it does not show up on the dash app.
I tried to change a bunch of things but only the 3 input cells and the heading show up. Is there anything I can do to make the table show up?
Thanks!