Hi,
I am trying to run a multi-input callback having updated Dash to 1.0.0. This code was working fine on dash 0.39.0 but not anymore and I can’t figure out why. It appears to be similar to the issue posted here:
Multiple callback error but not the same resolution in this instance.
My code is below:
app.layout = html.Div([
# START TABS
dcc.Tabs(id="tabs", children=[
###########
# TAB ONE
###########
dcc.Tab(label='Portfolio', children=[
# FIRST ROW
html.Div([
html.H5(
'',
id='update-time',
className='three columns',
style={"fontSize": "14",
'text-align': 'left'}
),
html.H5(
'',
id='live-update-text',
className='nine columns',
style={'text-align': 'center'}
),
], className='row'),
html.Br([]),
# SECOND ROW (net graph)
html.Div([
html.Div(id='graphs', children=dcc.Graph(id='my-graph')),
dcc.Interval(
id='interval-component',
interval=600*1000, # in milliseconds
n_intervals=0
)
]),
html.Br([]),
# THIRD ROW (in/out tables)
html.Div([
html.Div([
html.H6(['RBP & SWQP Outflows:'],
className="gs-header gs-table-header padded"),
dash_table.DataTable(
id='outflows-table',
columns=[{"name":i, "id":i} for i in column_names],
fixed_rows={ 'headers': True, 'data': 0 },
style_header={'fontWeight':'bold'},
style_cell={'textAlign': 'left'},
style_cell_conditional=[
{'if':{'column_id':('Date','DealDescription','LegTitle','LegDescription','DeliveryPoint')},
'textAlign':'left'},
{'if':{'column_id':'DealDescription'},
'width':'15%'},
{'if':{'column_id':'LegTitle'},
'width':'22%'},
{'if':{'column_id':'Date'},
'width':'12%'},
]
),
], className='six columns'),
html.Div([
html.H6(['RBP & SWQP Inflows:'],
className="gs-header gs-table-header padded"),
dash_table.DataTable(
id='inflows-table',
columns=[{"name":i, "id":i} for i in column_names],
fixed_rows={ 'headers': True, 'data': 0 },
style_header={'fontWeight':'bold'},
style_cell={'textAlign': 'left'},
style_cell_conditional=[
{'if':{'column_id':('Date','DealDescription','LegTitle','LegDescription','DeliveryPoint')},
'textAlign':'left'},
{'if':{'column_id':'DealDescription'},
'width':'15%'},
{'if':{'column_id':'LegTitle'},
'width':'22%'},
{'if':{'column_id':'Date'},
'width':'12%'},
]
),
], className='six columns'),
html.Div([
dcc.DatePickerRange(
id='date-picker-range',
display_format='YYYY-MM-DD',
min_date_allowed=datetime.datetime(2017,1,1),
max_date_allowed=datetime.datetime(2020,1,1),
start_date=datetime.date.today(),
end_date=datetime.datetime(2020,1,1),
initial_visible_month = datetime.datetime(2019,1,1)
),
])
])
])
])
])
#####################################################################################################
# CALLBACKS
#####################################################################################################
###################################
# GAS POSITION CALLBACKS
###################################
# Obtain position by location
@app.callback([Output('update-time', 'children'),
Output('live-update-text', 'children'),
Output('graphs','children'),
Output('outflows-table', 'data'),
Output('inflows-table', 'data'),
Output('large-portfolio-table','data')],
[Input('interval-component', 'n_intervals'),
Input('date-picker-range', 'start_date'),
Input('date-picker-range', 'end_date')
])
def update_metrics(satellite_json, start_date, end_date):
print('Starting Gas Position Code For Graph')
exec(open("pathtofile.py").read(), globals(), globals())
print('Graph Code Successfully Calculated')
satellite = pd.DataFrame(Gas_Portfolio)
satellite = satellite[satellite['AccountingDay'] <= monthdelta(datetime.datetime.today(),2).strftime("%Y-%m-%d 00:00:00")] # dates < today +2 month
satellite = satellite[satellite['AccountingDay'] >= monthdelta(datetime.datetime.today(),-1).strftime("%Y-%m-%d 00:00:00")] # dates > today -1 month
satellite = satellite.reset_index(drop=True)
satellite = satellite[satellite['AccountingDay'] <= monthdelta(datetime.datetime.today(),2).strftime("%Y-%m-%d 00:00:00")] # dates < today +2 month
satellite = satellite[satellite['AccountingDay'] >= monthdelta(datetime.datetime.today(),-1).strftime("%Y-%m-%d 00:00:00")] # dates > today -1 month
satellite = satellite.reset_index(drop=True)
satellite_json = satellite.to_json(date_format='iso', orient='split')
# Live position text
df = pd.read_json(satellite_json, orient='split')
df = pd.DataFrame(df).copy()
df['AccountingDay'] = pd.to_datetime(df.AccountingDay)
Today_RBP = df['Daily_RBP'][df.AccountingDay == datetime.datetime.today().strftime("%Y-%m-%d 00:00:00")].values[0]
Today_WAL = df['Daily_WAL'][df.AccountingDay == datetime.datetime.today().strftime("%Y-%m-%d 00:00:00")].values[0]
Today_Net = df['Daily_Portfolio'][df.AccountingDay == datetime.datetime.today().strftime("%Y-%m-%d 00:00:00")].values[0]
Today_Imb = df['Rolling APA Imbalance'][df.AccountingDay == datetime.datetime.today().strftime("%Y-%m-%d 00:00:00")].values[0]
print('Todays number code run')
# Post today's position
style = {'padding': '5px', 'fontSize': '16px'}
# Last update time
current_time = datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")
#######################
# First Graph
#######################
dff = pd.read_json(satellite_json, orient='split')
dff = pd.DataFrame(dff).copy()
dff['AccountingDay'] = pd.to_datetime(dff.AccountingDay)
figure = generate_graph(dff)
#######################
# In and Outflow tables
#######################
print('configuring outflows table')
Outflows_Data = Outflows_Table.copy()
Outflows_Data['Date'] = pd.to_datetime(Outflows_Data.AccountingDay)
Outflows_Data = Outflows_Data.drop(columns=['AccountingDay'])
Outflows_Data = Outflows_Data[['Date','FirmNomination','DealDescription','LegTitle','LegDescription','DeliveryPointName']]
print('configuring inflows table')
Inflows_Data = Inflows_Table.copy()
Inflows_Data['Date'] = pd.to_datetime(Inflows_Data.AccountingDay)
Inflows_Data = Inflows_Data.drop(columns=['AccountingDay'])
Inflows_Data = Inflows_Data[['Date','FirmNomination','DealDescription','LegTitle','LegDescription','DeliveryPointName']]
print('starting outflows callback')
data_out = Outflows_Data.loc[(Outflows_Data['Date'] >= start_date) & (Outflows_Data['Date'] <= end_date)]
data_out = data_out.to_dict("rows")
data_in = Inflows_Data.loc[(Inflows_Data['Date'] >= start_date) & (Inflows_Data['Date'] <= end_date)]
data_in = data_in.to_dict("rows")
#######################
# Large table (tab 3)
#######################
big_table = satellite.copy()
big_table = big_table.to_dict("rows")
return "Last Updated: {}".format(current_time), "Net WAL: {} GJ | Net RBP IPT {} GJ | Today Net Portfolio: {} GJ | End of day APA Imb {} GJ".format(Today_WAL,Today_RBP,Today_Net,Today_Imb), figure, data_out, data_in, big_table
Causing the following error:
Input(‘date-picker-range’, ‘end-date’)
AttributeError: ‘Div’ object has no attribute ‘keys’
Thank you in advance