-
Notifications
You must be signed in to change notification settings - Fork 334
/
smart_app.py
2543 lines (2437 loc) · 121 KB
/
smart_app.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Main class of Web application Shapash
"""
import copy
import random
import re
from math import isfinite, log10
import dash
import dash_bootstrap_components as dbc
import dash_daq as daq
import pandas as pd
import plotly.graph_objs as go
from dash import ALL, MATCH, dash_table, dcc, html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from flask import Flask
from shapash.utils.utils import truncate_str
from shapash.webapp.utils.callbacks import (
adjust_figure_layout,
create_dropdown_feature_filter,
create_filter_modalities_selection,
create_id_card_data,
create_id_card_layout,
determine_total_pages_and_display,
get_feature_contributions_sign_to_show,
get_feature_filter_options,
get_feature_from_clicked_data,
get_figure_zoom,
get_id_card_contrib,
get_id_card_features,
get_indexes_from_datatable,
get_selected_feature,
handle_group_display_logic,
handle_page_navigation,
select_data_from_bool_filters,
select_data_from_date_filters,
select_data_from_numeric_filters,
select_data_from_prediction_picking,
select_data_from_str_filters,
update_click_data_on_subset_changes_if_needed,
update_features_to_display,
)
from shapash.webapp.utils.explanations import Explanations
from shapash.webapp.utils.MyGraph import MyGraph
from shapash.webapp.utils.utils import check_row, get_index_type, round_to_k
def _create_input_modal(id, label, tooltip):
return dbc.Row(
[
dbc.Label(label, id=f"{id}_label", html_for=id, width=8),
dbc.Col(dbc.Input(id=id, type="number", value=0), width=4),
dbc.Tooltip(tooltip, target=f"{id}_label", placement="bottom"),
],
className="g-3",
)
class SmartApp:
"""
Bridge pattern decoupling the application part from SmartExplainer and SmartPlotter.
Attributes
----------
explainer: object
SmartExplainer instance to point to.
"""
def __init__(self, explainer, settings: dict = None):
"""
Init on class instantiation, everything to be able to run the app on server.
Parameters
----------
explainer : SmartExplainer
SmartExplainer object
settings : dict
A dict describing the default webapp settings values to be used
Possible settings (dict keys) are 'rows', 'points', 'violin', 'features'
Values should be positive ints
"""
# APP
self.server = Flask(__name__)
self.app = dash.Dash(
server=self.server,
external_stylesheets=[dbc.themes.BOOTSTRAP],
)
self.app.title = "Shapash Monitor"
if explainer.title_story:
self.app.title += " - " + explainer.title_story
self.explainer = explainer
# SETTINGS
self.logo = self.app.get_asset_url("shapash-fond-fonce.png")
self.color = explainer.plot._style_dict["webapp_button"]
self.bkg_color = explainer.plot._style_dict["webapp_bkg"]
self.title_menu_color = explainer.plot._style_dict["webapp_title"]
self.settings_ini = {
"rows": 1000,
"points": 1000,
"violin": 10,
"features": 20,
}
if settings is not None:
for k, v in self.settings_ini.items():
self.settings_ini[k] = (
settings[k] if k in settings and isinstance(settings[k], int) and 0 < settings[k] else v
)
self.settings = self.settings_ini.copy()
self.predict_col = ["_predict_"]
self.special_cols = ["_index_", "_predict_"]
if self.explainer.y_target is not None:
self.special_cols.append("_target_")
if self.explainer._case == "regression":
self.special_cols.append("_error_")
self.explainer.features_imp = self.explainer.state.compute_features_import(self.explainer.contributions)
if self.explainer._case == "classification":
self.label = self.explainer.check_label_name(len(self.explainer._classes) - 1, "num")[1]
self.selected_feature = self.explainer.features_imp[-1].idxmax()
self.max_threshold = int(
max([x.map(lambda x: round_to_k(x, k=1)).max().max() for x in self.explainer.contributions])
)
else:
self.label = None
self.selected_feature = self.explainer.features_imp.idxmax()
self.max_threshold = int(self.explainer.contributions.map(lambda x: round_to_k(x, k=1)).max().max())
self.list_index = []
self.subset = None
self.last_click_data = None
# DATA
self.explanations = Explanations() # To get explanations of "?" buttons
self.dataframe = pd.DataFrame()
self.round_dataframe = pd.DataFrame()
self.features_dict = copy.deepcopy(self.explainer.features_dict)
self.init_data()
# COMPONENTS
self.components = {"menu": {}, "table": {}, "graph": {}, "filter": {}, "settings": {}}
self.init_components()
# LAYOUT
self.skeleton = {"navbar": {}, "body": {}}
self.make_skeleton()
self.app.layout = html.Div([self.skeleton["navbar"], self.skeleton["body"]])
# CALLBACK
self.callback_fullscreen_buttons()
self.init_callback_settings()
self.callback_generator()
def init_data(self, rows=None):
"""
Method which initializes data from explainer object
"""
if hasattr(self.explainer, "y_pred"):
self.dataframe = self.explainer.x_init.copy()
if isinstance(self.explainer.y_pred, (pd.Series, pd.DataFrame)):
self.predict_col = self.explainer.y_pred.columns.to_list()[0]
self.dataframe = self.dataframe.join(self.explainer.y_pred)
elif isinstance(self.explainer.y_pred, list):
self.dataframe = self.dataframe.join(
pd.DataFrame(
data=self.explainer.y_pred, columns=[self.predict_col], index=self.explainer.x_init.index
)
)
else:
raise TypeError("y_pred must be of type pd.Series, pd.DataFrame or list")
else:
raise ValueError("y_pred must be set when calling compile function.")
if self.explainer.additional_data is not None:
self.dataframe = self.dataframe.join(self.explainer.additional_data)
self.features_dict.update(self.explainer.additional_features_dict)
self.dataframe["_index_"] = self.explainer.x_init.index
self.dataframe.rename(columns={f"{self.predict_col}": "_predict_"}, inplace=True)
if self.explainer.y_target is not None:
self.dataframe = self.dataframe.join(
self.explainer.y_target.rename(columns={self.explainer.y_target.columns[0]: "_target_"}),
)
if self.explainer._case == "regression":
self.dataframe = self.dataframe.join(self.explainer.prediction_error)
col_order = self.special_cols + self.dataframe.columns.drop(self.special_cols).tolist()
random.seed(79)
if rows is None:
rows = self.settings["rows"]
self.list_index = random.sample(
population=self.dataframe.index.tolist(), k=min(rows, len(self.dataframe.index.tolist()))
)
self.dataframe = self.dataframe[col_order].loc[self.list_index].sort_index()
self.round_dataframe = self.dataframe.copy()
for col in list(self.dataframe.columns):
typ = self.dataframe[col].dtype
if typ == float:
std = self.dataframe[col].std()
if isfinite(std) and std != 0:
digit = max(round(log10(1 / std) + 1) + 2, 0)
self.round_dataframe[col] = self.dataframe[col].map(f"{{:.{digit}f}}".format).astype(float)
def init_components(self):
"""
Initialize components (graph, table, filter, settings, ...) and insert it inside
components containers which are created by init_skeleton
"""
self.components["settings"]["input_rows"] = _create_input_modal(
id="rows",
label="Number of rows for subset",
tooltip="Set max number of lines for subset (datatable). \
Filter will be apply on this subset.",
)
self.components["settings"]["input_points"] = _create_input_modal(
id="points",
label="Number of points for plot",
tooltip="Set max number of points in feature contribution plots.",
)
self.components["settings"]["input_features"] = _create_input_modal(
id="features",
label="Number of features to plot",
tooltip="Set max number of features to plot in features \
importance and local explanation plots.",
)
self.components["settings"]["input_violin"] = _create_input_modal(
id="violin",
label="Max number of labels for violin plot",
tooltip="Set max number of labels to display a violin plot \
for feature contribution plot (otherwise a scatter \
plot is displayed).",
)
self.components["settings"]["name"] = dbc.Row(
[
dbc.Checklist(
options=[
{
"label": "Use domain name for \
features name.",
"value": 1,
}
],
value=[],
inline=True,
id="name",
style={"margin-left": "20px"},
),
dbc.Tooltip(
"Replace technical feature names by \
domain names if exists.",
target="name",
placement="bottom",
),
],
className="g-3",
)
self.components["settings"]["modal"] = dbc.Modal(
[
dbc.ModalHeader("Settings"),
dbc.ModalBody(
dbc.Form(
[
self.components["settings"]["input_rows"],
self.components["settings"]["input_points"],
self.components["settings"]["input_features"],
self.components["settings"]["input_violin"],
self.components["settings"]["name"],
]
)
),
dbc.ModalFooter(dbc.Button("Apply", id="apply", className="ml-auto")),
],
id="modal",
)
self.components["menu"] = dbc.Row(
[
dbc.Col(
[
html.Div(
daq.BooleanSwitch(
id="bool_groups",
on=True,
style={"display": "none"} if self.explainer.features_groups is None else {},
color=self.color[0],
label={
"label": "Groups",
"style": {
"fontSize": 18,
"color": self.color[0],
"fontWeight": "bold",
"margin-left": "5px",
},
},
labelPosition="right",
),
style={"margin-right": "35px"},
)
],
width="auto",
align="center",
),
dbc.Col(
[
html.H4(
[
dbc.Badge(
"Regression",
id="regression_badge",
style={"margin-right": "5px", "margin-left": "0px"},
color="",
),
dbc.Badge("Classification", id="classification_badge", color=""),
],
style={"margin-right": "5px"},
),
],
width="auto",
align="center",
style={"padding": "auto"},
),
dbc.Col(
dbc.Collapse(
dbc.Row(
[
# 2 columns to have class beside the dropdown buttons
dbc.Col(
[
dbc.Label("Class:", style={"color": "white", "margin": "0px"}),
],
align="center",
),
dbc.Col(
[
dcc.Dropdown(
id="select_label",
options=[],
value=None,
clearable=False,
searchable=False,
style={
"verticalAlign": "middle",
"zIndex": "1010",
"min-width": "160px",
"height": "100%",
},
)
],
style={"margin-right": "17px", "padding": "0px", "width": "auto"},
),
],
style={"margin": "0px"},
),
is_open=True,
id="select_collapse",
),
width="auto",
align="center",
style={"padding": "0px"},
),
dbc.Col(
[
html.Div(
[
html.Img(
id="settings",
title="settings",
alt="Settings",
src=self.app.get_asset_url("settings.png"),
height="40px",
style={"cursor": "pointer"},
),
self.components["settings"]["modal"],
]
)
],
align="center",
width="auto",
style={"padding": "0px"},
),
],
className="g-0",
justify="end",
)
self.adjust_menu()
self.components["table"]["dataset"] = dash_table.DataTable(
id="dataset",
data=self.round_dataframe.to_dict("records"),
tooltip_data=[
{column: {"value": str(value), "type": "text"} for column, value in row.items()}
for row in self.dataframe.to_dict("index").values()
],
tooltip_duration=2000,
columns=[{"name": i, "id": i} for i in self.dataframe.columns],
tooltip_header={
column: self.features_dict[column]
for column in self.dataframe.columns
if column not in self.special_cols
},
editable=False,
row_deletable=False,
virtualization=True,
page_action="none",
fixed_rows={"headers": True, "data": 0},
fixed_columns={"headers": True, "data": 0},
sort_action="native",
sort_mode="multi",
style_table={"overflowY": "auto", "overflowX": "auto"},
style_header={"height": "30px"},
style_cell={
"minWidth": "70px",
"width": "120px",
"maxWidth": "200px",
"textOverflow": "ellipsis",
},
)
self.components["graph"]["global_feature_importance"] = MyGraph(
figure=go.Figure(), id="global_feature_importance"
)
self.components["graph"]["feature_selector"] = MyGraph(figure=go.Figure(), id="feature_selector")
# Component for the graph prediction picking
self.components["graph"]["prediction_picking"] = MyGraph(figure=go.Figure(), id="prediction_picking")
self.components["graph"]["detail_feature"] = MyGraph(figure=go.Figure(), id="detail_feature")
# Component create to filter the dataset
self.components["filter"]["filter_dataset"] = dbc.Col(
[
dbc.Row(
html.Div(
id="main",
children=[
html.Div(
id="filters",
children=[
# Create Add Filter button
dbc.Button(
id="add_dropdown_button",
children="Add Filter",
color="warning",
size="sm",
style={"margin-right": "20px"},
),
# Create reset Filter button (disabled of no filters applied)
dbc.Button(
id="reset_dropdown_button",
children="Reset all existing filters",
color="warning",
disabled=True,
size="sm",
style={"margin-right": "20px"},
),
# Create explanation button
dbc.Button(
"?",
id="open_filter",
size="sm",
color="warning",
),
# Create popover on the explanation button
dbc.Popover(
"Click here to know how you can apply filters.",
target="open_filter",
body=True,
trigger="hover",
),
# Modal associated to the explanation button
dbc.Modal(
[
dbc.ModalHeader(dbc.ModalTitle("Filters explanation")),
dbc.ModalBody([html.Div(dcc.Markdown(self.explanations.filter))]),
dbc.ModalFooter(dbc.Button("Close", id="close_filter", color="warning")),
],
id="modal_filter",
centered=True,
size="lg",
),
# Div which will contains the filters
html.Div(id="dropdowns_container", children=[]),
],
)
],
)
),
dbc.Row(
html.Div(
[
html.Br(),
# Create Apply Filter button (Hidden if no filter to apply)
dbc.Button(
id="apply_filter",
children="Apply filters",
color="warning",
size="sm",
style={"display": "none"},
),
dbc.Label(
id="filtered_subset_info", children="Test", width="auto", style={"display": "none"}
),
],
)
),
],
style={"maxheight": "22rem", "height": "21rem", "zIndex": 800},
)
self.components["filter"]["index"] = dbc.Col(
dbc.Row(
[
dbc.Col(
[
dbc.Input(
id="index_id",
type=get_index_type(self.dataframe),
size="s",
placeholder="_index_",
debounce=True,
persistence=True,
style={"textAlign": "right"},
)
],
width={"size": 5},
style={"padding": "0px"},
),
dbc.Col(
[
html.Img(
id="validation",
alt="Validate",
title="Validate index",
src=self.app.get_asset_url("reload.png"),
height="30px",
style={"cursor": "pointer"},
)
],
width={"size": 1},
style={"padding": "0px"},
align="center",
),
dbc.Col(
[
dbc.Button(
"ID Card",
id="id_card",
color="warning",
style={"display": "none"},
),
dbc.Popover(
"Click here to visualize the identity card of the selected sample.",
target="id_card",
body=True,
trigger="hover",
),
dbc.Modal(
[
dbc.ModalHeader(
dbc.Col(
[
dbc.ModalTitle("Identity Card"),
dbc.Row(
[
dbc.Label("Sort by:", align="center", width="auto"),
dbc.Col(
[
dcc.Dropdown(
id="select_id_card_sorting",
options=[
{"label": "Label", "value": "feature_name"},
{
"label": "Contribution",
"value": "feature_contrib",
},
],
value="feature_name",
clearable=False,
searchable=False,
),
],
width=3,
),
dbc.Label("Order:", align="center", width="auto"),
dbc.Col(
[
dcc.Dropdown(
id="select_id_card_order",
options=[
{"label": "Ascending", "value": True},
{"label": "Descending", "value": False},
],
value=True,
clearable=False,
searchable=False,
),
],
width=3,
),
],
style={"margin-top": "0.5rem"},
),
dbc.Row(
[
dbc.Label("Label", width=3, style={"fontWeight": "bold"}),
dbc.Label("Value", width=5, style={"fontWeight": "bold"}),
dbc.Col(width=1),
dbc.Label(
"Contribution",
id="id_card_title_contrib",
width=3,
style={"fontWeight": "bold"},
),
],
style={"margin-top": "0.5rem", "margin-bottom": "-1rem"},
),
]
),
close_button=False,
),
dbc.ModalBody(id="id_card_body"),
dbc.ModalFooter(dbc.Button("Close", id="close_id_card", color="warning")),
],
id="modal_id_card",
centered=True,
size="xl",
scrollable=True,
),
],
width=5,
),
],
justify="center",
)
)
self.components["filter"]["threshold"] = dbc.Col(
[
dbc.Label("Threshold", html_for="slider", id="threshold_label"),
dcc.Slider(
min=0,
max=self.max_threshold,
value=0,
step=0.1,
marks={
f"{round(self.max_threshold * mark / 4)}": f"{round(self.max_threshold * mark / 4)}"
for mark in range(5)
},
id="threshold_id",
),
],
className="filter_dashed",
)
self.components["filter"]["max_contrib"] = dbc.Col(
[
dbc.Label("Features to display: ", id="max_contrib_label"),
dcc.Slider(
min=1,
max=min(self.settings["features"], len(self.explainer.x_init.columns)),
step=1,
value=min(self.settings["features"], len(self.explainer.x_init.columns)),
id="max_contrib_id",
),
],
className="filter_dashed",
)
self.components["filter"]["positive_contrib"] = dbc.Col(
[
dbc.Row(
[
dbc.Label("Contributions to display:", style={"font-size": "95%"}),
]
),
dbc.Row(
[
dbc.Col(
dbc.Checklist(
options=[{"label": "Positive", "value": 1}],
value=[1],
inline=True,
id="check_id_positive",
# define the font-size style
style={"font-size": "82%"},
),
style={"display": "inline-block"},
),
dbc.Col(
dbc.Checklist(
options=[{"label": "Negative", "value": 1}],
value=[1],
inline=True,
id="check_id_negative",
# define the font-size style
style={"font-size": "82%"},
),
style={"display": "inline-block"},
align="center",
),
],
className="g-0",
justify="center",
),
],
className="filter_dashed",
)
self.components["filter"]["masked_contrib"] = dbc.Col(
[
dbc.Label("Feature(s) to mask:"),
dcc.Dropdown(
options=[
{"label": key, "value": value}
for key, value in sorted(self.explainer.inv_features_dict.items(), key=lambda item: item[0])
],
value="",
multi=True,
searchable=True,
id="masked_contrib_id",
),
],
className="filter_dashed",
)
def make_skeleton(self):
"""
Describe the app skeleton (bootstrap grid) and initialize components containers
"""
self.skeleton["navbar"] = dbc.Container(
[
dbc.Row(
[
dbc.Col(
html.A(
dbc.Row(
[
dbc.Col([html.Img(src=self.logo, height="40px")], className="col-1"),
dbc.Col([html.H4("Shapash Monitor", id="shapash_title")]),
],
align="center",
style={"color": self.title_menu_color},
),
href="https://github.com/MAIF/shapash",
target="_blank",
),
# Change md=3 to md=2
md=2,
align="center",
width="100%",
style={"padding": "auto"},
),
dbc.Col(
[
html.A(
dbc.Row(
[
html.H3(
truncate_str(self.explainer.title_story, maxlen=40),
id="shapash_title_story",
style={"text-align": "center"},
)
]
),
href="https://github.com/MAIF/shapash",
target="_blank",
)
],
# Change md=3 to md=4
md=4,
align="center",
width="100%",
style={"padding": "auto"},
),
dbc.Col([self.components["menu"]], align="end", md=6, width="100%"),
],
style={"padding": "5px 15px", "verticalAlign": "middle", "width": "auto", "justify": "end"},
)
],
fluid=True,
style={"height": "100%", "backgroundColor": self.bkg_color},
)
self.skeleton["body"] = dbc.Container(
[
dbc.Row(
[
dbc.Col(
[
dbc.Card(
[
html.Div(
# To draw the global_feature_importance graph
self.draw_component("graph", "global_feature_importance"),
id="card_global_feature_importance",
# Position must be absolute to add the explanation button
style={"position": "absolute"},
),
dcc.Store(id="clickdata-store"),
dcc.Store(id="selected-clickdata-store"),
html.Div(
[
# Create a row to contain the buttons
dbc.Row(
[
# Placeholder column to center the second button
dbc.Col(
dbc.Button(
"Go Back",
id="goback_feature_importance",
size="sm",
color="warning",
style={"display": "none"},
),
width=2,
className="d-flex justify-content-start",
),
# Centered button column
dbc.Col(
html.Div(
[
dbc.Button(
"<",
id="page_left",
size="sm",
color="warning",
style={
"margin": "5px 0 5px 0",
"font-size": "12px",
"line-height": "1.2",
},
),
html.Div(
[
html.Span(
"1", id="page_feature_importance"
),
html.Span(" / ", id="separator"),
html.Span("1", id="total_pages"),
],
style={
"padding": "0 10px",
"align-self": "center",
},
),
dbc.Button(
">",
id="page_right",
size="sm",
color="warning",
style={
"margin": "5px 0 5px 0",
"font-size": "12px",
"line-height": "1.2",
},
),
],
id="page_viewer_feature_importance",
style={"display": "none"},
),
width=8,
className="d-flex justify-content-center",
),
# First button column
dbc.Col(
dbc.Button(
"?",
id="open_feature_importance",
size="sm",
color="warning",
),
width=2,
className="d-flex justify-content-end",
),
],
className="g-0",
align="center",
style={"width": "100%"},
),
# Create popover for the first button
dbc.Popover(
"Click here to have more information on Feature Importance graph.",
target="open_feature_importance",
body=True,
trigger="hover",
),
# Create modal associated to the first button
dbc.Modal(
[
# Modal title
dbc.ModalHeader(dbc.ModalTitle("Feature importance")),
dbc.ModalBody(
[
html.Div(
# Add explanation
dcc.Markdown(self.explanations.feature_importance)
),
# Here to add link in the modal
html.A(
"Click here for more details",
href="https://github.com/MAIF/shapash/blob/master/tutorial/plots_and_charts/tuto-plot03-features-importance.ipynb",
# open new browser tab
target="_blank",
style={"color": self.color[0]},
),
]
),
# button to close the modal
dbc.ModalFooter(
dbc.Button(
"Close", id="close_feature_importance", color="warning"
)
),
],
id="modal_feature_importance",
centered=True,
size="lg",
),
],
# position must be relative
style={
"position": "relative",
"display": "flex",
"justify-content": "space-between",
},
),
]
)
],
md=5,
style={"padding": "10px 10px 0px 10px"},
),
dbc.Col(
[
# Tabs that contain 3 children tab (Dataset,
# Dataset Filters and True Value Vs Pedicted Values)
dbc.Tabs(
[
# Tab which contains the datatable component
dbc.Tab(
# draw datatable component
self.draw_component("table", "dataset"),
# Tab name
label="Dataset",
className="card",
id="card_dataset",
# Style of the tab
style={"cursor": "pointer"},
label_style={"color": "black", "height": "30px", "padding": "0px 5px"},
# Style when the tab is activated
active_tab_class_name="fw-bold fst-italic",
active_label_style={
"border-top": "3px solid",
"border-top-color": self.color[0],
},
),
# Tab which contains components to filter the dataset
dbc.Tab(
dbc.Card(
dbc.CardBody(
html.Div(
# draw the component
self.draw_filter_table(),
id="card_filter_dataset",
# To add scroll in overflow y
style={"overflow-y": "scroll", "overflow-x": "hidden"},
)
),
style={"height": "24.1rem"},
),
# Tab name
label="Dataset Filters",
# Style of the tab
label_style={"color": "black", "height": "30px", "padding": "0px 5px"},
tab_style={
"border-left": "2px solid #ddd",
"border-right": "2px solid #ddd",
},
# Style when the tab is activated
active_tab_class_name="fw-bold fst-italic",
active_label_style={
"border-top": "3px solid",
"border-top-color": self.color[0],
},
),
# Tab which contains prediction picking graph
# and its explanation button
dbc.Tab(
dbc.Card(
[
html.Div(
# draw prediction picking graph