<pre>import dash
from dash import dcc
from dash import html
from dash import dash_table
import pandas as pd
import numpy as np
from OC import *
import pandas_ta as pta
findtargetcount=0
condition_ltp=""
condition_demand_supply=""
condition_call_vs_putt=""
condition_arbitrage=""
bullbear=""
all_data=[]
app = dash.Dash(__name__)
def getData():
data=returnn()
all_data.append(copy.deepcopy(data))
df = pd.DataFrame(all_data)
for i in range(1, len(df)):
def find_trend():
global findtargetcount,condition_ltp,condition_demand_supply,condition_call_vs_putt,condition_arbitrage,bullbear
val_ltp=df.loc[i, 'LTP']
val_ltppre=df.loc[i-1, 'LTP']
val_callvsput=df.loc[i, 'Call vs Put']
valcallvsputpre=df.loc[i-1, 'Call vs Put']
val_demandsupply=df.loc[i, 'Demand/Supply']
val_demandsupplypre=df.loc[i-1, 'Demand/Supply']
val_Arbitrage=df.loc[i, 'Arbitrage']
val_Arbitragepre=df.loc[i-1, 'Arbitrage']
if condition_ltp=="" and val_ltp>val_ltppre:
condition_ltp="bullish"
elif condition_ltp=="" and val_ltp<val_ltppre:
condition_ltp="bearish"
if condition_call_vs_putt=="" and val_callvsput>call_vs_put_standerd_val and val_callvsput>valcallvsputpre:
condition_call_vs_putt="bullish"
elif condition_call_vs_putt=="" and val_callvsput<call_vs_put_standerd_val and val_callvsput<valcallvsputpre:
condition_call_vs_putt="bearish"
if condition_demand_supply=="" and val_demandsupply>demand_supply_standerd_val and val_demandsupply>val_demandsupplypre:
condition_demand_supply="bullish"
elif condition_demand_supply=="" and val_demandsupply<demand_supply_standerd_val and val_demandsupply<val_demandsupplypre:
condition_demand_supply="bearish"
if condition_arbitrage=="" and val_Arbitrage>arbitrage_standerd_val and val_Arbitrage>val_Arbitragepre:
condition_arbitrage="bullish"
elif condition_arbitrage=="" and val_Arbitrage<arbitrage_standerd_val and val_Arbitrage<val_Arbitragepre:
condition_arbitrage="bearish"
if condition_ltp=="bullish" and condition_call_vs_putt=="bullish" and condition_demand_supply=="bullish" and condition_arbitrage=="bullish":
bullbear="BULLISH"
elif condition_ltp=="bearish" and condition_call_vs_putt=="bearish" and condition_demand_supply=="bearish" and condition_arbitrage=="bearish":
bullbear="BEARISH"
else:
bullbear="NOT CONFIRMED"
return bullbear
df.loc[i, 'ZONE']=find_trend()
return df.to_dict('records')
app.layout = html.Div([
html.H4('Option Chain'),
dcc.Interval('table-update', interval = 60000*1, n_intervals = 1),
dash_table.DataTable(
id = 'table',
data = getData())])
@app.callback(
dash.dependencies.Output('table','data'),
[dash.dependencies.Input('table-update', 'n_intervals')])
def updateTable(n):
time.sleep(1)
return getData()
if __name__ == '__main__':
app.run_server(debug=False)
What I have tried:
I am using Python3.9. And I am a new learner in Python. In my Dash Data Table, I want to color each cell light green, if the value grater than 0 and green if the value grater than 0 and also grater than the value of the same cell of the previous row. I have tried in many ways but I failed. I think the dash data table and call back function makes it difficult to me to change colour of each cell. Please help me to modify my code for my purpose. Thanks.