Plots not displayed

Hello Dash community,

I have got a plot that depends on three dropdowns.
When I run the app, the code runs fine.
However, no plot is displayed when one has made one’s selection.
Could anyone help me?

I have attached my code below.

Thanks,

Emmanuel

from dash import Dash, dcc, Input, Output, html
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
import numpy as np
from datetime import datetime
import pdb

df = pd.read_csv(‘trades.csv’)
assets_ls = df[‘symbol’].unique().tolist()
app = Dash(name)
app.layout = html.Div(children=[html.H1(‘Test - Odum Research’),
html.Br(),
dcc.Dropdown(id=‘volume_plot’,
options=[‘intraday_volume’,‘patterns’],value=‘intraday_volume’),
dcc.Dropdown(id=‘asset’,options=assets_ls,value=‘BTC-25SEP20’,multi=True),
dcc.Dropdown(id=‘timeframe’,multi=False),
dcc.Graph(id=‘intraday_volume’,figure={})])
@app.callback(
[Output(component_id=‘timeframe’,component_property=‘value’),
Output(component_id=‘timeframe’,component_property=‘options’)],
Input(component_id=‘volume_plot’,component_property=‘value’)
)
def checklist(value):
if value == ‘intraday_volume’:
return ‘main_content’,[‘main_content’]
elif value == ‘patterns’:
return ‘5min’, [‘1s’,‘30s’,‘1min’,‘5min’,‘15min’,‘30min’,‘1H’]
else:
return ‘’,[‘NaN’]

@app.callback(
Output(component_id=‘intraday_volume’,component_property=‘figure’),
[Input(component_id=‘asset’,component_property=‘value’),
Input(component_id=‘volume_plot’,component_property=‘value’),
Input(component_id=‘timeframe’,component_property=‘value’)]
)
def display_intraday_volume(volume_plot,asset,timeframe):
print(volume_plot)
print(asset)
print(timeframe)
temp_df = df.copy()
temp_df[‘timestamp’] = temp_df[‘timestamp’].apply(lambda x: datetime.fromtimestamp(x/1e6))
if volume_plot == ‘intraday_volume’:
pdb.set_trace()
if timeframe == ‘main_content’:
pdb.set_trace()
temp_df = temp_df[[‘symbol’,‘timestamp’,‘amount’]]
if not asset:
fig = {}
else:
if isinstance(asset,str):
fig = px.histogram(data_frame=temp_df.loc[temp_df[‘symbol’].isin([asset]),:],
x=‘timestamp’,y=‘amount’,
color=‘symbol’,labels={‘sum of amount’:‘Number of Shares Traded’,
‘timestamp’: ‘Day in July 2020’})
else:
fig = px.histogram(data_frame=temp_df.loc[temp_df[‘symbol’].isin(asset), :],
x=‘timestamp’, y=‘amount’, color=‘symbol’,
labels={‘sum of amount’: ‘Number of Shares Traded’,
‘timestamp’: ‘Day in July 2020’})
elif volume_plot == ‘patterns’:
pdb.set_trace()
if not asset:
fig = {}
else:
pdb.set_trace()
temp_df[‘date’] = [pd.to_datetime(timestamp).date() for timestamp in temp_df[‘timestamp’]]
temp_df.set_index(‘timestamp’,inplace=True)
temp_df = temp_df[[‘symbol’, ‘date’, ‘amount’]]
temp_df = temp_df.resample(timeframe).agg({‘symbol’:‘first’,‘date’:‘first’,‘amount’:‘sum’})
temp_df[‘time’] = list(map(lambda x: x.strftime(’%H:%M:%S’),temp_df.index))
temp_df = temp_df.loc[temp_df[‘symbol’].isin(asset), :]
pdb.set_trace()
temp_df = temp_df.groupby(‘time’).agg({‘symbol’: ‘first’,
‘date’: ‘first’, ‘amount’: ‘sum’}).reset_index(False)
temp_df = pd.pivot_table(temp_df, columns=‘date’, index=‘time’, values=‘amount’)
aggregated_df = pd.concat([temp_df.apply(np.min,axis=1),temp_df.apply(lambda x: x.quantile(q=.25),axis=1),
temp_df.apply(lambda x: x.quantile(q=.75),axis=1)],axis=1)
aggregated_df = aggregated_df.rename(
columns={aggregated_df.columns[_]:i for _,i in enumerate([‘1st_quantile’,‘median’,‘3rd_quantile’])})
temp_df = temp_df.reset_index(False).sort_values(by=‘time’)
temp_df = pd.melt(temp_df, id_vars=‘time’,value_name=‘volume’)
aggregated_df = aggregated_df.reset_index(False).sort_values(by=‘time’)
pdb.set_trace()
fig = px.scatter(temp_df,x=‘time’,color=‘date’,y=‘volume’,)
fig.add_trace(go.Scatter(x=aggregated_df[‘time’],
y=aggregated_df[‘1st_quantile’],name=‘1st_quantile’,line={‘dash’:‘dash’}))
fig.add_trace(go.Scatter(x=aggregated_df[‘time’],
y=aggregated_df[‘median’],name=‘median’,line={‘dash’:‘dot’}))
fig.add_trace(go.Scatter(x=aggregated_df[‘time’],
y=aggregated_df[‘3rd_quantile’],name=‘3rd_quantile’,line={‘dash’:‘dash’}))
else:
fig = {}
return fig

if name == ‘main’:
app.run_server(debug=True)

csv files:
exchange,symbol,timestamp,local_timestamp,id,side,price,amount
deribit,ETH-25SEP20,1593561640656000,1593561640665430,ETH-18083995,buy,227.55,100
deribit,BTC-25SEP20,1593561642083000,1593561642090778,83913108,buy,9201.5,100
deribit,BTC-25SEP20,1593561642083000,1593561642090778,83913109,buy,9201.5,100
deribit,ETH-25SEP20,1593561646090000,1593561646098113,ETH-18083998,buy,227.55,100
deribit,BTC-25DEC20,1593561646724000,1593561646732510,83913111,sell,9267,1300
deribit,BTC-25DEC20,1593561646724000,1593561646732510,83913112,sell,9267,1300
deribit,BTC-25DEC20,1593561646724000,1593561646732510,83913113,sell,9267,7400
deribit,BTC-25SEP20,1593561646782000,1593561646785744,83913114,sell,9201.5,1700
deribit,BTC-25SEP20,1593561646782000,1593561646785744,83913115,sell,9201.5,1500
deribit,BTC-25SEP20,1593561646782000,1593561646785744,83913116,sell,9201.5,60
deribit,BTC-25SEP20,1593561646782000,1593561646785744,83913117,sell,9201.5,500
deribit,BTC-25SEP20,1593561646795000,1593561646799539,83913118,sell,9201,1500
deribit,BTC-25SEP20,1593561646795000,1593561646799539,83913119,sell,9201,550
deribit,BTC-25SEP20,1593561646795000,1593561646799539,83913120,sell,9201,1700
deribit,BTC-25DEC20,1593561646819000,1593561646824851,83913121,sell,9267,2600
deribit,BTC-25DEC20,1593561646819000,1593561646824851,83913122,sell,9267,1300
deribit,BTC-25DEC20,1593561646821000,1593561646826332,83913123,sell,9266.5,1930
deribit,BTC-25DEC20,1593561646831000,1593561646835771,83913124,sell,9266.5,2120
deribit,BTC-25DEC20,1593561646832000,1593561646840767,83913125,sell,9266.5,2340

Hi Emmanuel,

please put your code in code tags. You find this in the editor menü ( Symbol ist this here </>)

BR
Torsten

Just from a quick look at this code …
Based on this callback function, and how you defined your inputs, it should be:

display_intraday_volume(asset, volume_plot, timeframe):

volume_plot == 'intraday_volume':

This is never going to happen, because the variable volume_plot is actually tied to your asset dropdown values

Not sure if this solves your entire problem, but it might put you in the right direction.