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

-- 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()

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.