-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstructures.py
More file actions
1397 lines (1266 loc) · 50.1 KB
/
structures.py
File metadata and controls
1397 lines (1266 loc) · 50.1 KB
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
import dash_bootstrap_components as dbc
from dash import dcc
from dash import html
import pandas as pd
from dash import dash_table
import warnings
import plotly.graph_objects as go
import stylesheet as ss
import constants
pd.options.mode.chained_assignment = None
warnings.simplefilter(action="ignore",category = FutureWarning)
def make_table(df, id, id2= "default", page_size = 25):
table = dash_table.DataTable(
id={
'type': id,
'index': id2
},
data=df.to_dict('records'),
columns=[{'id': i, 'name': i, 'presentation': 'markdown'} if "link" in i.lower() else {"name": i, "id": i} for i in df.columns],
page_size=page_size,
editable=False,
row_selectable=False,
row_deletable=False,
style_table=ss.TABLE_STYLE,
style_header=ss.TABLE_HEADER,
style_cell=ss.TABLE_CELL,
style_data_conditional=ss.TABLE_CONDITIONAL
),
return table
def make_table_dict(df , id, page_size = 25, ):
table = dash_table.DataTable(
id=id,
data=df,
columns=[{'id': i, 'name': i, 'presentation': 'markdown'} if "link" in i.lower() else {"name": i, "id": i} for i in df[0].keys()],
page_size=page_size,
editable=False,
row_selectable=False,
row_deletable=False,
style_table=ss.TABLE_STYLE,
style_header=ss.TABLE_HEADER,
style_cell=ss.TABLE_CELL,
style_data_conditional=ss.TABLE_CONDITIONAL
),
return table
def basket_review_table(df):
table = dash_table.DataTable(
id="basket_review_table", #id = basket_review_table (passed in app)
data=df.to_dict('records'),
columns=[{"name": i, "id": i} for i in df.columns],
page_size=25,
editable=False,
style_header=ss.TABLE_HEADER,
style_cell=ss.TABLE_CELL,
row_deletable=True,
selected_rows=[i for i in range(len(df))]
)
return table
def always_available_table(df):
table = dash_table.DataTable(
id="always_available_table",
data=df.to_dict('records'),
#columns=[{"name": i, "id": i} for i in df.columns],
page_size=25,
editable=False,
style_header=ss.TABLE_HEADER,
style_cell=ss.TABLE_CELL,
row_deletable=False,
selected_rows=[i for i in range(len(df))]
)
return table
def main_titlebar(app, title_text):
titlebar = html.Div([
html.Div([
html.Img(
src = app.get_asset_url("explore_lower_full_logo_regular.png"),
className = "llc_logo",
id = "llc_logo"
),
html.A(
href="https://ukllc.ac.uk/",
children=[
]),
],
className = "row_layout"
),
],
className = "title_div"
)
return titlebar
def build_sidebar_list(blocks_df, current_basket = [], sch_open =[], tab_open = "None"):
sidebar_children = []
# Get data sources
sources = blocks_df["source"].drop_duplicates().sort_values()
# Attribute tables to each study
for schema in sources:
source_name = blocks_df.loc[blocks_df["source"] == schema]["source_name"].values[0]
tables = blocks_df.loc[blocks_df["source"] == schema]["table"].sort_values(key=lambda col: col.str.lower())
table_names = blocks_df.loc[blocks_df["source"] == schema]["table_name"]
table_type = blocks_df.loc[blocks_df["source"] == schema]["Type"].values[0]
if table_type.lower() == "lps":
style_classname = "LPS_accordion"
collapse_style_classname = "LPS_collpase"
elif table_type.lower() == "linked":
style_classname = "linked_accordion"
collapse_style_classname = "linked_collpase"
collapse_open = False
if schema in sch_open and sch_open[schema] == True:
collapse_open = True
# Tooltip
source_tooltip = dbc.Tooltip(
source_name,
delay = {"show" : 50, "hide":0},
target= {
"type":'button_text',
"index" : schema
},
placement="right",
)
# CHECKBOXES
checkbox_items = []
checkbox_active = []
for table in tables:
checkbox_items += [schema+"-"+table]
if schema+"-"+table in current_basket:
checkbox_active += [schema+"-"+table]
checkbox_col = html.Div(
children= dcc.Checklist(
checkbox_items,
value = checkbox_active,
id= {
"type":'shopping_checklist',
"index" : schema
},
className = "shopping_checkbox",
style = ss.CHECKBOX_STYLE
),
id= {
"type":'checkbox_col',
"index" : schema
},
)
# SCHEMA
source = html.Div([
html.Div(
[
html.Div (
[
html.Div(
[html.Div(
schema,
id = {
"type":'button_text',
"index" : schema},
className = "button_text"
),
],
id= {
"type":'source_title',
"index" : schema
},
className = "source_title",
n_clicks = 0
),
html.Button(
"",
id= {
"type":'source_collapse_button',
"index" : schema
},
className = "source_collapse_button"
)
],
className = "row_layout"
)
],
className = "collapse-button"
),
],
className = style_classname
)
# TABLES
table = dbc.Collapse([
html.Div(children = [
dcc.Tabs(
id={
'type': 'table_tabs',
'index': schema
},
vertical=True,
value= "None", #by default, otherwise app_state.table
parent_className='custom-tabs',
className = "table_tabs_container",
children = [
dcc.Tab(
label = table,
value = schema+"-"+table,
id={
'type': 'sidebar_table_item',
'index': schema+"-"+table
},
className = "table_tab",
selected_className="table_tab--selected"
)
for table in tables
],
),
checkbox_col
],
className = "list_and_checkbox_div"
),
],
id= {
"type":'source_collapse',
"index" : schema
},
className = collapse_style_classname,
is_open = collapse_open
)
sidebar_children += [source, source_tooltip, table]
study_list = html.Div(
sidebar_children,
id='schema_accordion',
className= "content_accordion",
)
return study_list
def make_sidebar_catalogue(df):
catalogue_div = html.Div(
build_sidebar_list(df),
id = "sidebar_list_div",
)
return catalogue_div
def make_sidebar_title():
sidebar_title = html.Div([
html.Div(html.H2("UK LLC Data Catalogue")),
html.Div([
html.Div([
html.P("Showing full catalogue"),
], id = "sidebar_filter"),
dbc.Button("Reset filters", id = "clear_search2", className = "reset_button")
],
className = "row_layout")
], id = "sidebar_title")
return sidebar_title
def make_sidebar_left(sidebar_title, sidebar_catalogue):
sidebar_left = html.Div([
dbc.Collapse(
[
sidebar_title,
sidebar_catalogue
]
,
id="sidebar-collapse",
is_open=True,
dimension="width",
)
],
id = "sidebar_left_div")
return sidebar_left
def make_about_box(app):
landing_box = html.Div([
html.H1("Placeholder for an attention grabbing header"),
dbc.Accordion(
[
dbc.AccordionItem(
"Browse the UK LLC Data Discovery Portal to discover data from the 20+ longitudinal population studies that contribute data to the UK LLC Trusted Research Environment (TRE). The metadata encompass study-collected and linked datasets, including health, geospatial and non-health routine records. Use this tool to select datasets from our catalogue for a new data request or data amendment.etc",
title="What is the UK LLC (placeholder)",
className = "body_accordion",
id = "about_collapse1"
),
dbc.AccordionItem(
"Placeholder text",
title="Understanding the UK LLC data catalogue",
className = "body_accordion",
id = "about_collapse2"
),
dbc.AccordionItem(
"We have data. Its probably worth your time to take a look at it.",
title="Explore the data",
className = "body_accordion",
id = "about_collapse3"
),
dbc.AccordionItem(
"select the datasets you want etc",
title="Build a shopping basket",
className = "body_accordion",
id = "about_collapse4"
),
dbc.AccordionItem(
html.Iframe(
src="https://www.youtube.com/embed/QfyaG3zemcs",
title="YouTube video player",
allow="accelerometer, autoplay, clipboard-write, encrypted-media, gyroscope, picture-in-picture",
id = "embed_video"
),
title="User guide etc",
className = "about_accordion_item",
id = "about_collapse5"
),
dbc.AccordionItem(
"More things, please let me know",
title="Some other heading about the app/crucial information we need to share",
className = "body_accordion",
id = "about_collapse6"
),
],
always_open=True,
className = "about_accordion"
),
html.Div(
[
html.P("Placeholder for bottom stuff like logos or what have you", className="padding_p"),
],
id = "about_content_div7",
),
],
id = "body_about",
className = "body_box",
)
return landing_box
def make_search_box(df, themes):
'''
Search box TODO:
Source type checkboxes - LPS, NHS, Geo, Admin
Include - takes all possible sources
Topic Checkboxes - take all recognised topic tags/keywords
Collection age
Collections time
We need to make a table with all of these fields in it for every table:
type, topics, collection age, collection time
Ideally we have a search index table, with 1 row per table. If we get a match, we look it up in a info table.
'''
sources = list(df["source"].drop_duplicates().sort_values().values)
doc_box = html.Div([
html.Div([
html.H1("UK LLC Explore"),
html.Hr(),
html.Div([
html.P("Search our catalogue of longitudinal and linked data and build a data request."),
html.P("This version of Explore is a stopgap. We are working on a new version with improved \
search functionality, metadata coverage and quality.")
]),
],
className = "text_block" ,
id = "intro_div"),
html.Div([
html.Div([
dcc.Checklist(
['Study data', 'Linked data'],
['Study data', 'Linked data'],
inline=True,
id = "include_type_checkbox"
),
html.Div([
dcc.Input("", id ="main_search", className="search_field", placeholder = "Search query"),
html.Button("search", id = "search_button"),
],
className = "row_layout",
id = "main_search_row")
],
className = "style_div",
id = "search_style_div"
),
dbc.Accordion([
dbc.AccordionItem(
html.Div([
dbc.Accordion([
dbc.AccordionItem(
html.Div([
html.Div([
html.H3("Include"),
dcc.Dropdown(sources, id = "include_dropdown", multi = True),
],
className = "container_div",
),
html.Div([
html.H3("Exclude"),
dcc.Dropdown(sources, id = "exclude_dropdown", multi = True)
],
className = "container_div"
),
],
className = "row_layout"
),
title="Data Source",
className = "search_accordion",
id = "data_source_accordion"
)
]),
dbc.Accordion([
dbc.AccordionItem(
html.Div([
dcc.Dropdown(themes, id = "tags_search", multi = True),
],
className = "container_div"
),
title="Topic Checkboxes",
className = "search_accordion",
id = "topic_accordion"
)
]),
dbc.Accordion([
dbc.AccordionItem(
html.Div([
dcc.RangeSlider(min = 0, max = 100, step = 5, value=[0, 100], id='collection_age_slider'),
],
className = "container_div"
),
title="Collection Age",
className = "search_accordion",
id = "collection_age_accordion"
)
]),
dbc.Accordion([
dbc.AccordionItem(
html.Div([
dcc.RangeSlider(min = 0, max = 9, step = 1, value=[0, 9], id='collection_time_slider',
marks={
0: '1940',
1: "1950",
2: '1960',
3: "1970",
4: "1980",
5: "1990",
6: "2000",
7: "2010",
8: "2020",
9: "2030"}
,
)
],
className = "container_div"
),
title="Collection Time",
className = "search_accordion",
id = "collection_time_accordion"
)
]),
dbc.Button("Reset filters", id = "clear_search1", className = "reset_button")
],
className = "container_div"
),
title = "Advanced Options",
)
],
id = "advanced_options_collapse",
start_collapsed=True
),
dcc.Tabs(
id = "search_type_radio",
value = "Sources",
children = [
dcc.Tab(label = "Sources", value = "Sources"),
dcc.Tab(label = "Datasets", value = "Datasets"),
dcc.Tab(label = "Variables", value = "Variables")
]
),
dcc.Loading(
children = [
html.Div([
html.Div([], id = "search_text"),
html.Div(
dcc.Checklist(["Show values"], ["Show values"], id = "toggle_values", className = "button"),
),
html.Div([], id = "search_metadata_div")
],
className = "container_div"
),
],
id = "search_loading",
type = "circle",
parent_className = "loading",
className = "loading_spinner"
)
],
className = "shadow_block"
)
],
id = "body_search",
className = "body_box"
)
return doc_box
def make_study_box():
study_box = html.Div([
html.Div([
html.H1("Source", id = "source_category"),
html.Hr(),
html.Div([
html.H4("Browse and select a source for more information", id = "study_title"),
]),
],
className = "desc_title",
),
html.Div([
html.Div([
html.Div(["Its a description"], id = "source_description_div", className = "text_block"),
html.Div(["placeholder for summary table"], id = "study_summary", className = "container_div"),
], className = "container_line_50"),
html.Div([
dcc.Tabs([
dcc.Tab(label="Age Distribution", children = [
dcc.Loading(children = [
html.Div(["placeholder for age table"], id = "source_age_graph", className = "container_div")
], type = "circle",)
]),
dcc.Tab(label="Linkage Rates", children =[
dcc.Loading(children = [
html.Div(["Placeholder for pie char"], id = "source_linkage_graph", className = "container_div")
], type = "circle",)
]),
dcc.Tab(label="Coverage", children =[
#dbc.Tooltip(
# "Coverage is deduced from NHS England linkage from a participant's most recent interaction with healthcare services. It does not reflect coverage at the time of collection. Information is only available for participants living in England.",
# target="map_tooltip",
#),
dcc.Loading(children = [
html.Div([
html.P("Coverage is deduced from NHS England linkage from participants' most recent interaction with healthcare services. It does not reflect coverage at the time of collection. Information is only available for participants living in England.", className = "small_text"),
#html.I(className = "bi bi-info-circle", id = "map_tooltip" ),
html.Div([
],
id = "Map", ),],
className = "tab_div"
)
], type = "circle",)
])
], className = "tab_parent"),
], className = "container_line_50" )
],
className = "row_layout",
id = "source_row",
),
html.Div([], id = "study_table_div"),
html.Div(text_block("Studies may have other data not currently available through Explore. These data could be made available pending negotiation with the study."))
],
id = "body_source",
className = "body_box"
)
return study_box
def make_block_box(children = [None, None]):
dataset_box = html.Div([
html.Div([
html.H1("UK LLC Dataset", id = "dataset_header"),
html.Hr(),
html.Div([
html.P("Browse and select a dataset for more information", id = "dataset_title"),
]),
],
className = "desc_title",
),
html.Div([
html.Div([
html.Div(["Placeholder description"], id = "dataset_description_div", className = "text_block"),
html.Div(["placeholder for summary table"], id = "dataset_summary", className = "container_div"),
], className = "container_line_50"),
html.Div([
dcc.Tabs([
dcc.Tab(label="Age Distribution", children =[
html.Div(["placeholder for age table"], id = "dataset_age_graph", className = "container_div")
]),
dcc.Tab(label="Linkage Rates", children =[
html.Div(["Placeholder for pie char"], id = "dataset_linkage_graph", className = "container_div")
])
], className = "tab_parent"),
],
className = "container_line_50" ),
],
className = "row_layout",
id = "dataset_row"),
html.Div(make_table(pd.DataFrame(data = {"col1":["val1"]}), "search_metadata_table"), id = "dataset_variables_div"),
],
id = "body_dataset",
className = "body_box"
)
return dataset_box
def make_modal_background():
return html.Div([], id = "modal_background", className = "modal_background")
def FAQ():
body = html.Div([
html.H1("Frequently Asked Questions"),
html.Hr(className = "center_hr"),
html.Div([
html.H2("1. How do I request data from the UK LLC"),
html.P("Contact access@ukllc.ac.uk who will direct you on the process of starting a project and making a data request.")
],
className = "FAQ_QA"
),
html.Div([
html.H2("2. Why is your FAQ section so empty?"),
html.P("We haven't had many questions yet. If you have any, please send them to support@ukllc.ac.uk")
],
className = "FAQ_QA"
),
html.Div([
html.H2(""),
html.P("")
],
className = "FAQ_QA"
),
html.Div([
html.H2(""),
html.P("")
],
className = "FAQ_QA"
),
])
'''
FAQ ideas:
1. How do I request data from the UK LLC
Contact access@ukllc.ac.uk who will direct you on the process of starting a project and making a data request.
2. Why is your FAQ section so empty?
We haven't had many questions yet. If you have any, please send them to support@ukllc.ac.uk
'''
return body
def contact_us():
body = html.Div([
html.H1("Contact us"),
html.Hr(className = "center_hr"),
html.P("We welcome questions, so please do get in touch. If your query is about:"),
html.Ul([
html.Li(
html.Div([
html.P("The data held in the TRE, please contact: support@ukllc.ac.uk"),
],
),
className = "FAQ_QA"
),
html.Li(
html.Div([
html.P("Applying to access the TRE, please contact: access@ukllc.ac.uk"),
],
className = "FAQ_QA"
),
),
html.Li(
html.Div([
html.P("Your LPS joining the UK LLC, please contact: info@ukllc.ac.uk"),
],
className = "FAQ_QA"
),
),
])
])
return body
def modal():
modal = html.Div(
[
dbc.Modal(
[
dbc.ModalBody([
dbc.Button(
html.I(className = "bi bi-x-lg", ), id = "modal_close", className="offcanvas_close", n_clicks=0
),
html.Div([
FAQ()
],
className = "modal_body",
id = "modal_body"
)
]
)
],
id="modal",
is_open=False,
className = "modal"
),
]
)
return modal
def make_basket_review_offcanvas():
offcanvas = html.Div([dbc.Offcanvas(
[
dbc.Button(html.I(className = "bi bi-x-lg", ), id = "offcanvas_close", n_clicks = 0),
html.Div([
html.P("If you have selected any of the following NHS E datasets: \
CANCER, GDPPR, HESAE, HESAPC, HESOP, PCM, \
you are required to supply a list of medical codes for inclusion in your project. \
The code list template is available ", className = "codeitem"),
html.A(href = "https://apply.ukllc.ac.uk/apply/view_document/codelist_template", \
target="_blank", children = ["here"], className = "codeitem"),
html.P(" and is submitted during the application process. \
For more information on medical coding systems: ", className = "codeitem"),
html.A(href = "https://guidebook.ukllc.ac.uk/docs/linked_health_data/nhs_england/coding/coding_intro",
target="_blank", children = ["Guidebook"], className = "codeitem"),
],
id = "codelist_download"),
html.Div([
text_block("Default datasets (automatically included):")
],
id = "basket_review_always_selected_text"),
html.Div([
text_block("")
],
id = "basket_review_always_selected"),
html.Div([
text_block("You currently have no additional datasets in your selection. Use the checkboxes in the UK LLC Data Catalogue sidebar to add datasets.")
],
id = "basket_review_text_div"),
html.Div([
dash_table.DataTable(
id="basket_review_table", #id = basket_review_table (passed in app)
data=None,#df.to_dict('records'),
columns=None,#[{"name": i, "id": i} for i in df.columns],
page_size=20,
editable=False,
row_selectable=False,
row_deletable=True, # TODO test this?
style_header=ss.TABLE_HEADER,
style_cell=ss.TABLE_CELL,
)
],
id = "basket_review_table_div"),
html.Div([
dbc.Button(
"clear selection",
id="clear_basket_button",
className = "red_button",
n_clicks=0,
),
dbc.Button(
"Save",
id="save_button",
className = "blue_button",
n_clicks=0,
),
],
className = "row_layout")
],
is_open=False,
id = "offcanvas_review",
className = "offcanvas",
backdrop = True,
placement = "end"
),
])
return offcanvas
def make_basket_review_box():
# DEPRICATED?
basket_review_box = html.Div([
#Main body is a table with Source, block, description, checkbox
#Clear all button at top of checklist col - far from save
#Big save button at the bottom
#Recommend box? bottom or RHS
# Get list of selected tables & doc as df
html.Div([
text_block("You currently have no datasets in your selection. Use the checkboxes in the UK LLC Data Catalogue sidebar to add datasets.")
],
id = "basket_review_text_div"),
html.Div([
dash_table.DataTable(
id="basket_review_table", #id = basket_review_table (passed in app)
data=None,#df.to_dict('records'),
columns=None,#[{"name": i, "id": i} for i in df.columns],
page_size=20,
editable=False,
row_selectable=False,
row_deletable=True, # TODO test this?
style_header=ss.TABLE_HEADER,
style_cell=ss.TABLE_CELL,
)
],
id = "basket_review_table_div"),
html.Div([
dbc.Button(
"clear selection",
id="clear_basket_button",
n_clicks=0,
),
dbc.Button(
"Save",
id="save_button",
n_clicks=0,
),
],
className = "row_layout")
],
id = "body_review",
className = "body_box",
)
return basket_review_box
def sidebar_collapse_button():
button = html.Button(
html.I(className = "bi bi-list", ),
id="sidebar-collapse-button",
n_clicks=0,)
return button
def make_body(sidebar, app, spine, themes):
return html.Div([
sidebar,
sidebar_collapse_button(),
html.Div([
make_search_box(spine, themes),
footer(app),
],
id = "body_content"),
],
id="body")
def make_variable_div(id_type, data = "None"):
variable_div = dcc.Store(id = id_type, data = data)
return variable_div
def make_variable_div_list(id_type, indices):
divs = []
for i in indices:
divs += [html.Div([],key = "0", id = {"type":id_type, "index":str(i)})]
return divs
def make_hidden_items(hidden_items):
return html.Div(
hidden_items,
className = "Hidden"
)
def make_app_layout(titlebar, body, account_section, variable_divs, location ):
app_layout = html.Div([titlebar, body, account_section, make_modal_background(), make_basket_review_offcanvas(),modal(), location, ] + variable_divs, id="app")
return app_layout
def make_info_box(df, harmony_link=None):
out_text = []
for col in df.columns:
#row
if ("website" not in col.lower()) and ("link" not in col.lower()):
row = html.Div([
# First column
html.Div([
html.B(col +":")
], className = "info_box_left"),
# Second column
html.Div([
html.P(str(df[col].values[0]).replace("\n", ""))
], className = "info_box_right")
])
else:
row = html.Div([
# First column
html.Div([
html.B(col)
], className = "info_box_left"),
# Second column
html.Div([
dcc.Markdown(str(df[col].values[0]).replace("\n", ""))
], className = "info_box_right")
])
[{'id': x, 'name': x, 'presentation': 'markdown'} if x == 'Link(s)' else {'id': x, 'name': x} for x in df.columns],
out_text.append(row)
if harmony_link is not None:
row = html.Div([
# First column
html.Div([
html.B("Harmonise metadata:")
], className = "info_box_left"),
# Second column
html.Div([
html.A([html.Img(src="/assets/logos/harmony.svg", alt="Harmony", width="1.2em", height="1.287em",
style={"height": "1.2em", "width": "1.287em", "padding-top": "0px",
"padding-bottom": "0px", "padding-left": "0px", "padding-right": "0px",
"margin-top": "0px", "margin-bottom": "0px", "margin-left": "0px",
"margin-right": "0px", "border-top": "0px", "border-bottom": "0px",
"border-left": "0px", "border-right": "0px", "border": "0px",
"box-sizing": "0px"
}), " "], href=harmony_link, target="harmony",
style={"vertical-align": "top", "margin-top": "0px", "text-decoration": "none"}),
html.A([html.Span("Import into Harmony", id="tooltip-target", style={"vertical-align": "top", "margin-top": "0px"})],
href=harmony_link, target="harmony", style={"vertical-align": "top", "margin-top": "0px"}),
dbc.Tooltip("Use AI to compare 2 datasets to find similar variables", target = "tooltip-target"),
], className = "info_box_right", style={"vertical-align": "top", "margin-top":"0px"}, id = "tooltip"),
])
[{'id': x, 'name': x, 'presentation': 'markdown'} if x == 'Link(s)' else {'id': x, 'name': x} for x in df.columns],
out_text.append(row)
return html.Div(out_text)
def make_schema_description(schemas):
# Make the study tab variables
schemas = schemas[constants.SOURCE_SUMMARY_VARS.keys()].rename(columns = constants.SOURCE_SUMMARY_VARS)
schemas["Number of datasets"] = schemas["Number of datasets"].astype(int)
schemas["Participant count"] = schemas["Participant count"].astype(int)
# covid only flag
if schemas["Covid Restrictions"].iloc[0] == 1.0:
schemas["Covid Restrictions"] = "Study data can only be used for COVID-19 research"
elif schemas["Covid Restrictions"].iloc[0] == 0.0:
schemas["Covid Restrictions"] = "Study data can be used for any public good research"
else:
schemas = schemas.drop(columns="Covid Restrictions")
# Copyright
if schemas["Copyright"].iloc[0] is None or schemas["Copyright"].iloc[0] == "":
schemas = schemas.drop(columns="Copyright")
return make_info_box(schemas)
def make_block_description(blocks, harmony_link=None):
# Make the study tab variables
blocks = blocks[constants.BLOCK_SUMMARY_VARS.keys()].rename(columns = constants.BLOCK_SUMMARY_VARS)
try:
blocks["Participants Included"] = blocks["Participants Included"].astype(int)
except (TypeError, ValueError):
blocks["Participants Included"] = "N/A"
blocks["Collection Duration"] = blocks["Collection Start"] + " - " + blocks["Collection End"]
blocks = blocks.drop(columns = ["Collection Start", "Collection End"])
print("DEUBG:", blocks.columns)
blocks = blocks.fillna( "Not currently available" )
# if no restrictions on dataset then remove
if blocks["Restrictions on use"].iloc[0] == "Not currently available":
blocks = blocks.drop(columns="Restrictions on use")
# covid only flag
if blocks["Covid Restrictions"].iloc[0] == 1.0:
blocks["Covid Restrictions"] = "Data can only be used for COVID-19 research"
elif blocks["Covid Restrictions"].iloc[0] == 0.0:
blocks["Covid Restrictions"] = "Data can be used for any public good research"
else:
blocks = blocks.drop(columns="Covid Restrictions")
return make_info_box(blocks, harmony_link=harmony_link)
def make_blocks_table(df):
df = df[constants.BLOCK_TABLE_VARS.keys()].rename(columns = constants.BLOCK_TABLE_VARS)
df.insert(loc = 5, column = "Collection Duration", value = df["Collection Start"] + " - " + df["Collection End"])
df = df.drop(columns = ["Collection Start", "Collection End"])
table = make_table(df, "tables_desc_table", page_size=5)
return table
def make_metadata_table(df):
df = df
return make_table(df, "metadata_table", page_size= 30)