-
Notifications
You must be signed in to change notification settings - Fork 0
/
dash_sample_style_data_conditionals.py
99 lines (88 loc) · 2.96 KB
/
dash_sample_style_data_conditionals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# https://dash.plotly.com/datatable/style
# https://github.com/Zhiji022/Kelowna_cultural_plan_survey_analysis/blob/256fe704ad47a48c075339fba0975dc586d5d5e6/callbacks/second_tab/table_style.py
# https://stackoverflow.com/questions/56259327/dash-datatable-conditional-cell-formatting-isnt-working
# https://community.plotly.com/t/datatable-style-data-conditional-several-conditions/30990
the_buys = (orders['side'] == 'B')
style={
'textAlign': 'right',
'color': colors['cyber_yellow'] * or red
}
the_sells = (orders['side'] == 'S') and (orders['price'] == quotes['bid_price'])
style={
'textAlign': 'right',
'color': colors['green_text']
}
style_data_conditional=[
{
"if": {"row_index": (orders['side'] == 'B')},
'color': colors['cyber_yellow'],
'fontWeight': 'bold'
},
{
'if': {'column_id': 'Goal'},
'fontWeight': 'bold',
'backgroundColor':'#E0F9FF',
'textAlign': 'center'
}],
style_cell_conditional=[
{
'if': {'column_id': c},
'textAlign': 'left'
} for c in ['Date', 'Region']
],
style_data_conditional=[
{
'if': {'row_index': 'odd'},
'backgroundColor': 'rgb(248, 248, 248)'
}
],
style_data_conditional=[
{
'if': {
'column_id': i,
'filter_query': '{' + str(i) + '} > 100'
},
'backgroundColor': '#99EE6B'
} for i in col_list
] + [
{
'if' : {
'column_id' : i,
'filter_query' : '{' + str(i) + '} < 100'
},
'backgroundColor' : '#FF7373'
} for i in col_list
]
style_data_conditional=[{
"if": {
'column_id': 'price',
'filter_query': '{side} eq "B"'
# ^ ^ <-- required braces
},
"color": colors['cyber_yellow']
}] + [{
"if": {
'column_id': 'price',
'filter_query': '{side} eq "S"'
# ^ ^ <-- required braces
},
"color": colors['green_text']
}]
# The error happens because you compare two pandas.Series objects with different indices. A simple solution could be to compare just the values in the series. Try it:
# TBD Nuertey Odzeyem, can use this approach too as an alternative to .isin() but .isin() is preferred.
if df1['choice'].values != df2['choice'].values
style_data_conditional = [{
'if': {
'column_id': 'ask_price',
"row_index": x
},
'color': colors['red_text']
} for x in quotes[quotes['timestamped'].isin(orders.loc[orders[orders['side'] == "B"].index, 'timestamped'])].index
] + [{
'if': {
'column_id': 'bid_price',
"row_index": x
},
'color': colors['green_text']
} for x in quotes[quotes['timestamped'].isin(orders.loc[orders[orders['side'] == "S"].index, 'timestamped'])].index
]