# HOW TO RETURN SUBPLOTS TO dcc. Graph FROM CALLBACKS. I am trying to add volume bar chart to OHLC CHART AND THEN RETURN IT TO DCC.GRAPH USING CALLBACKS

**URL:** <https://community.plotly.com/t/how-to-return-subplots-to-dcc-graph-from-callbacks-i-am-trying-to-add-volume-bar-chart-to-ohlc-chart-and-then-return-it-to-dcc-graph-using-callbacks/58120>\
**Category:** Dash Python\
**Created:** [November 3, 2021, 12:40pm UTC](https://community.plotly.com/t/how-to-return-subplots-to-dcc-graph-from-callbacks-i-am-trying-to-add-volume-bar-chart-to-ohlc-chart-and-then-return-it-to-dcc-graph-using-callbacks/58120 "2021-11-03T12:40:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamlesh\_Parihar](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@Kamlesh\_Parihar](https://community.plotly.com/u/Kamlesh_Parihar)\
**Post date:** [November 3, 2021, 12:40pm UTC](https://community.plotly.com/t/how-to-return-subplots-to-dcc-graph-from-callbacks-i-am-trying-to-add-volume-bar-chart-to-ohlc-chart-and-then-return-it-to-dcc-graph-using-callbacks/58120/1 "2021-11-03T12:40:23Z")

</div>

# -_- coding: utf-8 -_-

“”"  
Created on Wed Oct 27 22:11:53 2021

@author: Kamlesh Parihar  
“”"

# -_- coding: utf-8 -_-

“”"  
Created on Tue Oct 26 22:21:35 2021

@author: Kamlesh Parihar

The dash\_core\_components package is deprecated. Please replace  
`import dash_core_components as dcc` with `from dash import dcc`  
import dash\_core\_components

The dash\_html\_components package is deprecated. Please replace  
`import dash_html_components as html` with `from dash import html`  
import dash\_html\_components

“”"

import dash  
import dash\_core\_components as dcc  
import dash\_html\_components as html  
from dash.dependencies import Input, Output  
import plotly.graph\_objects as go  
import pandas as pd  
import numpy as np  
from datetime import datetime  
from maxdqv import mdp, mdq, sn, mtv,hd  
from plotly.subplots import make\_subplots

MDP=mdp()  
MDQ=mdq()  
MTV=mtv()  
HD=hd()  
N5001=pd.read\_excel(“D:\to be deleted 6 October 2019\Share Market\Historical Data\Open Interest Sheet\Bhavcopy Data NIFTY500\NIFTY 500.xlsx”,“NIFTY 500”)  
N5002=N5001[‘Symbol’].values.flatten().tolist()

# N5002

#List1=[‘STOCKS WITH MAX. DEL. PER.’,‘STOCKS WITH MAX DEL. BY QTY’,‘STOCKS WITH MAX. TRADING VOL.’, ‘STOCKS WITH HIGH DEL.’]  
N5002  
List=[‘MDP1’,‘MDQ1’,‘MTV1’,‘HD1’,‘N500’]

# List

# type(List)

dflist=pd.DataFrame(List,columns=[‘List’])  
dfmdp=pd.DataFrame(MDP,columns=[‘MDP1’])  
dfmdq=pd.DataFrame(MDQ,columns=[‘MDQ1’])  
dfmtv=pd.DataFrame(MTV,columns=[‘MTV1’])  
dfhd=pd.DataFrame(HD,columns=[‘HD1’])  
N500=pd.DataFrame(N5002,columns=[‘N500’])  
consdf=pd.concat([dfmdp,dfmdq,dfmtv,dfhd,N500],axis=1)

#consdf[‘MDTV1’]

# READING THE STOCK DATA AND DROPPING THE CELLS NOT REQUIRED FOR PLOTTING

app = dash.Dash( **name** )

app.layout =html.Div([

# Creates HEADING 1

```
html.H1(children = 'Stock Data',
        style = {
            'textAlign' : 'center',
            'color' : '#456FBV'                
        },
),

```

# Creates HEADING 2

```
html.Div(children= "Kamlesh Parihar Creation",
         style = {
            'textAlign' : 'center',
            'color' : '#456FBV'                
         }                          
),  
html.Div(children= "SELECTION CRITERIA",
         style = {
            'textAlign' : 'left',
            'color' : '#456FBV'                
         }                          
),  

  # dcc.Dropdown(id ='fcriteria1',
  # placeholder='SELECTION CRITERIA',
  # style={'width':'30%'},
  # options=[{'label': x, 'value' : x } for x in (dflist.List.unique())],
  # value=dflist['List'].values[0],
               
  # ),
dcc.RadioItems(id ='radio',
               options=[{'label': x, 'value' : x } for x in (dflist.List.unique())],
               value=dflist['List'].values[0],
),  
   
html.Div(children= "SELECT A STOCK",
         style = {
            'textAlign' : 'left',
            'color' : '#456FBV'                
         }                          
),  
dcc.Dropdown(id='stocks', options=[], 
             placeholder='SELECT STOCK NAME',
             searchable=True,
             style={'width':'40%'},
),

dcc.Graph(id="graph",figure={}),

         
#dcc.Dropdown(id = 'dropdown', 
            #options=[
                 # {'label':i,'value':i} for i in dfmdp['stocks'].unique()
                 # ],
            # style ={'width':'30%'}

```

])

@app.callback(  
dash.dependencies.Output(‘stocks’, ‘options’),  
[dash.dependencies.Input(‘radio’, ‘value’)])  
def dropdown\_options(listvalues):  
return [{‘label’: c, ‘value’: c} for c in consdf[listvalues]]

@app.callback(  
[dash.dependencies.Output(“graph”, “figure”)],  
[dash.dependencies.Input(“stocks”, “value”)])  
def display\_candlestick(value):  
df=sn(value,70) # sn is an user defined function from my own library.  
df=df.drop(columns=[‘SYMBOL’,‘S\_NO’, ‘DELIV\_PER’, ‘DELIV\_QTY’, ‘TPrice\_Change’,‘NPrice\_Change’,‘NO\_OF\_TRADES’, ‘TURNOVER\_LACS’])  
fig = make\_subplots(rows=2, cols=1)  
fig.add\_traces(go.Figure(go.Candlestick(  
x=df[‘DATE’],  
open=df[‘OPEN\_PRICE’],  
high=df[‘HIGH\_PRICE’],  
low=df[‘LOW\_PRICE’],  
close=df[‘CLOSE\_PRICE’]),  
row=1,col=1))  
fig.add\_trace(go.Figure(go.Bar( x=df[‘DATE’], y=df[‘TTL\_TRD\_QNTY’]),row=2,col=1))  
fig.update\_layout(xaxis\_rangeslider\_visible=True)  
return fig

if **name** == ‘ **main** ’:  
app.run\_server()

---

<div class="post-metadata">

**Author:** ![jlfsjunior](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jlfsjunior/32/16061_2.png) [@jlfsjunior](https://community.plotly.com/u/jlfsjunior)\
**Post date:** [November 3, 2021, 3:49pm UTC](https://community.plotly.com/t/how-to-return-subplots-to-dcc-graph-from-callbacks-i-am-trying-to-add-volume-bar-chart-to-ohlc-chart-and-then-return-it-to-dcc-graph-using-callbacks/58120/2 "2021-11-03T15:49:23Z")

</div>

Firstly, could you please format your question and title, so it makes it easier for others to read when they are asking a similar question?

Regarding the question itself, I believe the problem is in the `fig.add_trace` statements, since you are passing a `go.Figure` to the trace. Just pass directly `go.Candlestick` and `go.Bar` and your problem should be solved.
