-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.R
More file actions
922 lines (730 loc) · 31.3 KB
/
server.R
File metadata and controls
922 lines (730 loc) · 31.3 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
library(Rautoml)
options(shiny.maxRequestSize=3000000*1024^2)
function(input, output, session){
# ---- Progress overlay for cold-start feedback ----
update_progress <- function(msg) {
waiter::waiter_show(
html = tagList(
spin_loaders(id = 2, style="width:56px;height:56px;color:#7BC148;"),
tags$br(),
tags$span(msg, style="color:#555;font-size:14px;margin-top:12px;display:block;")
),
color = "#FFF"
)
}
update_progress("Loading packages...")
source("server/auth.R")
source("Server/homepage_translation_labels.R", local = TRUE)
register_homepage_labels(output, session, get_rv_labels)
USER = user_auth(input, output, session)
authed_started = reactiveVal(FALSE)
observeEvent(USER$logged_in, {
req(isTRUE(USER$logged_in))
waiter_show(
html = spin_loaders(id = 3, style="width:56px;height:56px;color:#7BC148;"),
color = "#FFF"
)
if (authed_started()) return()
authed_started(TRUE)
app_username = USER$username
model_training_caret_pb = Attendant$new("model_training_caret_pb", hide_on_max = TRUE)
data_upload_id_pb = Attendant$new("data_upload_id_pb", hide_on_max = TRUE)
model_metrics_caret_pb = Attendant$new("model_metrics_caret_pb", hide_on_max = TRUE)
deploy_models_caret_pb = Attendant$new("deploy_models_caret_pb", hide_on_max = TRUE)
predict_models_caret_pb = Attendant$new("predict_models_caret_pb", hide_on_max = TRUE)
predict_endpoint_models_caret_pb = Attendant$new("predict_endpoint_models_caret_pb", hide_on_max = TRUE)
generate_research_questions_outcome_pb = Attendant$new("generate_research_questions_outcome_pb", hide_on_max = TRUE)
generate_research_questions_additional_analysis_pb = Attendant$new("generate_research_questions_additional_analysis_pb", hide_on_max = TRUE)
feature_engineering_perform_preprocess_pb = Attendant$new("feature_engineering_perform_preprocess_pb", hide_on_max = TRUE)
model_training_caret_metrics_download_all_zip_pb = Attendant$new("model_training_caret_metrics_download_all_zip_pb", hide_on_max = TRUE)
#### ---- Input validators ---------------------------------------------------
source("server/input_validators.R")
#### ---- Create needed folders for datasets and logs ------------------------
source("server/create_dirs.R", local=TRUE)
#### ---- FastAPI base URL réactif (lié au champ fastapi_base) ----
source("R/utils_logging.R")
DEFAULT_API_BASE <- Sys.getenv("FASTAPI_BASE", "http://api:8000")
source("server/automl_controls_server.R")
source("server/train_model_server.R")
source("R/utils_api.R")
source("server/deploy_model_server.R", local=TRUE)
source("ui/deploy_model_ui.R", local=TRUE)
source("server/predict_pycaret_server.R", local = TRUE)
source("server/history_actions.R", local = TRUE)
source("server/history_transform_actions.R", local = TRUE)
source("server/history_visualize_auto_actions.R", local = TRUE)
source("server/history_visualize_custom_actions.R", local = TRUE)
api_base <- reactive({
val <- input$fastapi_base
if (is.null(val) || !nzchar(trimws(val))) {
DEFAULT_API_BASE
} else {
trimws(val)
}
})
observe({
expand_label <- get_rv_labels("sidebar_toggle_expand_menu")
collapse_label <- get_rv_labels("sidebar_toggle_menu_aria")
session$sendCustomMessage(
type = "sidebarLabels",
message = list(
expand = expand_label,
collapse = collapse_label
)
)
})
# Send sidebar toggle labels to JS (reactive-safe)
sent_sidebar_labels <- reactiveVal(FALSE)
observe({
req(rv_lang$labelling_file_df)
req(!sent_sidebar_labels())
expand_label <- get_rv_labels("sidebar_toggle_expand_menu")
collapse_label <- get_rv_labels("sidebar_toggle_menu_aria")
session$sendCustomMessage(
"sidebarLabels",
list(expand = expand_label, collapse = collapse_label)
)
sent_sidebar_labels(TRUE)
})
#### ---- Placeholder for reactive values ------------------------------------
##### -------- Currently selected dataset ------------------------------------
rv_current = reactiveValues(
dataset_id = NULL
, metadata_id = NULL
, data = NULL
, selected_vars = NULL
, selected_var = NULL
, working_df = NULL
, current_filter = NULL
, current_filter_reset = NULL
, manage_data_title_explore = NULL
, missing_prop = NULL
, has_missing_data_check=FALSE
, manage_data_title_transform = NULL
, merge_data_title_merge = NULL
, transform_data_select_vars = NULL
, vartype = NULL
, changed_variable_type_log = NULL
, transform_data_plot_df = NULL
, renamed_variable_log = NULL
, transform_data_quick_plot_out = NULL
, recoded_variable_labels_log = NULL
, missing_prop_df = NULL
, created_missing_values_log = NULL
, outlier_values = NULL
, handle_missing_values_log = NULL
, handle_outlier_values_log = NULL
, transform_data_plot_missing_data_out = NULL
, quick_explore_summary = NULL
, max_tockens = 10000
, seed = 9991
, outcome = NULL
, vartype_all = NULL
)
##### ---- Sidebar history actions -----------------------------------
history_actions_server(input, output, session, rv_current, get_rv_labels)
history_transform_actions_server(input, output, session, rv_current, get_rv_labels)
history_visualize_auto_actions_server(input, output, session, rv_current, plots_sec_rv, get_rv_labels)
history_visualize_custom_actions_server(input, output, session, rv_current, plots_sec_rv, get_rv_labels)
#####------------------Plots Reactive-------------------
plots_sec_rv <- reactiveValues(
plot_rv=NULL
,tab_rv=NULL
,plot_bivariate_auto=NULL
,plot_corr = NULL
)
##### --------- Meta data ---------------------------------------------
rv_metadata = reactiveValues(
upload_logs = NULL
, dataset_ids = NULL
, data_summary_str = NULL
, data_summary_skim = NULL
, data_summary_summary = NULL
, data_summary_summarytools = NULL
)
rv_database <- reactiveValues(schema_list = NULL
, table_list = NULL
, conn = NULL
, schema_selected = NULL
, table_selected = NULL
, df_table = data.frame()
, df_table_str = NULL
, query_table_name = NULL
, database_host = NULL
, database_name = NULL
, database_user = NULL
, database_pass = NULL
, details = NULL
)
## ---
rv_omop<- reactiveValues(
url = NULL )
## LLM/GAI
rv_generative_ai = reactiveValues(
history = NULL
)
## Reactive values for ML/AI module
rv_ml_ai = reactiveValues(
session_id = NULL
, seed_value = NULL
, dataset_id = NULL
, analysis_type = NULL
, task = NULL
, outcome = NULL
, model_formula = NULL
, partition_ratio = NULL
, predictors = NULL
, excluded_predictors = NULL
, ml_ai_setup_result = NULL
, history = NULL
, split = NULL
, train_df = NULL
, test_df = NULL
, preprocessed = NULL
, feature_engineering_preprocessed_log = NULL
, at_least_one_model = FALSE
)
## RV to hold UIs
rv_ui_models = reactiveValues(
model_training_caret_models_ols_check = NULL
, model_training_caret_models_ols_advance_control = NULL
)
## Train control caret
rv_train_control_caret = reactiveValues(
method = "cv"
, number = 5
, repeats = NA
, search = "grid"
, verboseIter = FALSE
, savePredictions = FALSE
, classProbs = TRUE
)
## Trained models
rv_training_models = reactiveValues(
ols_model = NULL
, ols_param = FALSE
, ols_name = NULL
, ols_trained_model = NULL
, rf_model = NULL
, rf_param = FALSE
, rf_name = NULL
, rf_trained_model = NULL
, gbm_model = NULL
, gbm_param = FALSE
, gbm_name = NULL
, gbm_trained_model = NULL
, xgbTree_model = NULL
, xgbTree_param = FALSE
, xgbTree_name = NULL
, xgbTree_trained_model = NULL
, xgbLinear_model = NULL
, xgbLinear_param = FALSE
, xgbLinear_name = NULL
, xgbLinear_trained_model = NULL
, svmRadial_model = NULL
, svmRadial_param = FALSE
, svmRadial_name = NULL
, svmRadial_trained_model = NULL
, svmLinear_model = NULL
, svmLinear_param = FALSE
, svmLinear_name = NULL
, svmLinear_trained_model = NULL
, svmPoly_model = NULL
, svmPoly_param = FALSE
, svmPoly_name = NULL
, svmPoly_trained_model = NULL
, glmnet_model = NULL
, glmnet_param = FALSE
, glmnet_name = NULL
, glmnet_trained_model = NULL
, lasso_model = NULL
, lasso_param = FALSE
, lasso_name = NULL
, lasso_trained_model = NULL
, ridge_model = NULL
, ridge_param = FALSE
, ridge_name = NULL
, ridge_trained_model = NULL
, knn_model = NULL
, knn_param = FALSE
, knn_name = NULL
, knn_trained_model = NULL
, nnet_model = NULL
, nnet_param = FALSE
, nnet_name = NULL
, nnet_trained_model = NULL
, avNNet_model = NULL
, avNNet_param = FALSE
, avNNet_name = NULL
, avNNet_trained_model = NULL
, pls_model = NULL
, pls_param = FALSE
, pls_name = NULL
, pls_trained_model = NULL
, rpart_model = NULL
, rpart_param = FALSE
, rpart_name = NULL
, rpart_trained_model = NULL
, mlpWeightDecayML_model = NULL
, mlpWeightDecayML_param = FALSE
, mlpWeightDecayML_name = NULL
, mlpWeightDecayML_trained_model = NULL
, naive_bayes_model = NULL
, naive_bayes_param = FALSE
, naive_bayes_name = NULL
, naive_bayes_trained_model = NULL
, all_trained_models = NULL
)
rv_training_results = reactiveValues(
models = NULL
, train_metrics_df = NULL
, test_metrics_objs = NULL
, post_model_metrics_objs = NULL
, control_parameters = NULL
, tuned_parameters = NULL
)
# Update training results when a new model is trained
automl_controls_server(
id = "automl_controls",
rv_current = rv_current,
rv_ml_ai = rv_ml_ai,
api_base = api_base,
app_username = app_username
)
train_model_server(
id = "train_model",
rv_current = rv_current,
rv_ml_ai = rv_ml_ai,
api_base = api_base
)
# End update training
# ---- (A) Detect if a complete PyCaret run is available (leaderboard displayed) ----
.can_show_by_train <- reactive({
curr_ds <- rv_current$dataset_id %||% rv_ml_ai$dataset_id
isTRUE(rv_ml_ai$status %in% c("Finished","Finished_NoPlots")) &&
!is.null(rv_ml_ai$leaderboard) && NROW(rv_ml_ai$leaderboard) > 0 &&
isTRUE(nzchar(rv_ml_ai$trained_dataset_id)) &&
identical(rv_ml_ai$trained_dataset_id, curr_ds)
})
observeEvent(rv_current$dataset_id, {
# If we change the dataset, we clean up the transient state linked to the previous train.
if (!identical(rv_current$dataset_id, rv_ml_ai$trained_dataset_id)) {
rv_ml_ai$leaderboard <- NULL
rv_ml_ai$leaderboard_full <- NULL
rv_ml_ai$test_leaderboard <- NULL
rv_ml_ai$test_leaderboard_full <- NULL
rv_ml_ai$models <- NULL
rv_ml_ai$eval_metrics <- NULL
rv_ml_ai$eval_plots <- NULL
rv_ml_ai$status <- NULL
}
}, ignoreInit = FALSE)
# ---- (B) Datasets with pre-trained models (historical) ----
.get_models_index_csv <- function() file.path(getwd(), app_username, "logs", "models", "index.csv")
dataset_has_history <- reactive({
idx <- .get_models_index_csv()
if (!file.exists(idx)) return(FALSE)
df <- tryCatch(read.csv(idx, stringsAsFactors = FALSE), error = function(e) NULL)
if (is.null(df) || !"dataset_id" %in% names(df)) return(FALSE)
ds <- rv_ml_ai$dataset_id %||% rv_current$dataset_id
if (is.null(ds) || !nzchar(ds)) return(FALSE)
any(df$dataset_id == ds & (df$framework %in% c("PyCaret","pycaret","Pycaret")))
})
# Expose known datasets for the Deploy module (used in its selector)
observe({
idx <- .get_models_index_csv()
if (!file.exists(idx)) return(invisible(NULL))
df <- tryCatch(read.csv(idx, stringsAsFactors = FALSE), error = function(e) NULL)
if (is.null(df) || !"dataset_id" %in% names(df)) return(invisible(NULL))
rv_current$known_datasets <- sort(unique(df$dataset_id))
})
.can_show_deploy <- reactive({
isTRUE(.can_show_by_train()) || isTRUE(dataset_has_history())
})
# (keep this if you still use it on the JS side)
output$can_show_deploy <- reactive({ .can_show_deploy() })
outputOptions(output, "can_show_deploy", suspendWhenHidden = FALSE)
# ---- Deploy tab UI container ----
output$deploy_container <- renderUI({
if (!isTRUE(.can_show_deploy())) return(NULL) # => onglet totalement vide
column(width = 12, deployment_ui("deploy"))
})
outputOptions(output, "can_show_deploy", suspendWhenHidden = FALSE)
## Deployed models table
rv_deploy_models = reactiveValues(
trained_models_table = NULL
)
## Deployed models
rv_deployed_models = reactiveValues()
## Reactive values to stock AutoML leaderboard
rv_automl <- reactiveValues(
leaderboard = NULL
)
#### ---- App title ----------------------------------------------------
source("server/header_footer_configs.R", local=TRUE)
app_title()
###-------App Footer--------------------------
footer_language_translation()
###-------Menu Translate---------
menu_translation()
#### ---- Change language ----------------------------------------------------
output$change_language = change_language
source("server/change_language_update.R", local = TRUE)
change_language_update()
#### ---- Upload data UI --------------------------------------------
source("ui/upload_data.R", local = TRUE)
output$upload_type = upload_type
#### ---- Upload dataset/files UI --------------------------------------------
source("server/input_files.R", local = TRUE)
output$input_files = input_files
#### ---- Show uploaded datasets UI --------------------------------------------
output$show_uploaded = show_uploaded
#### ---- Data upload form -----------------------------------------------
source("ui/upload_form.R", local = TRUE)
output$study_name = study_name
output$study_country = study_country
output$additional_info = additional_info
output$submit_upload = submit_upload
#### ---- Databse and API connection warning ---------------------
db_api_con_future
#### ---- Upload datasets ----------------------------------------
source("server/upload_data.R", local = TRUE)
upload_data_server()
#### ---- Database integration ----------------------------------------
source("server/database_integration.R", local = TRUE)
database_integration_server()
#### --- Database related form elements ---###
output$db_type = db_type
output$db_host = db_host
output$db_name = db_name
output$db_user = db_user
output$db_pwd = db_pwd
output$db_connect = db_connect
output$db_schema_list = db_schema_list
output$db_table_list = db_table_list
output$db_custom_query = db_custom_query
output$db_run_query = db_run_query
output$db_port = db_port
output$db_disconnect = db_disconnect
output$db_tab_query = db_tab_query
output$existing_connection = existing_connection
source("server/omop_analysis.R", local = TRUE)
omop_analysis_server()
stderr_file_path <- file.path(getwd(), app_username, "output", "dq_stderr.txt")
stderr_content<-create_log_reader(stderr_file_path)
#### ---- Collect logs ----------------------------------------
source("server/collect_logs.R", local = TRUE)
collect_logs_server()
#### ---- Display uploaded datasets ----------------------------------------
source("server/display_uploaded_data.R", local = TRUE)
display_uploaded_data_server()
#### ---- Delete uploaded dadatsets ----------------------------------------
source("server/delete_uploaded_data.R", local = TRUE)
delete_uploaded_data_server()
#### ---- Update logfiles based on existing datasets -------------------####
source("server/update_logs.R", local = TRUE)
update_logs_server()
#### ---- Manage data ----------------------------------------------
##### ---- Select data ---------------------------------------------
source("server/select_data.R", local = TRUE)
select_data_server()
manage_data_show_server()
##### ---- Display meta data for the selected dataset ---------------------------------------------
source("server/display_metadata.R", local = TRUE)
display_selected_metadata_server()
reset_display_selected_metadata_server()
##### ---- Currently selected data ---------------------------------------------
source("server/selected_data.R", local = TRUE)
currently_selected_data_server()
##### ----Generate summary stats for the row data -------------------
source("server/manage_data_summary.R", local = TRUE)
generate_data_summary_server()
display_data_summary_server()
#### ----- Explore data -----------------------------------------------
source("server/explore_data.R", local = TRUE)
explore_data_server()
explore_data_subactions_server()
##----User Defined Visualization section-----------------------
source("ui/user_defined_visualization_header.R", local = TRUE)
output$user_output_type = user_output_type
output$user_tab_options = user_tab_options
output$user_calc_var = user_calc_var
#output$user_strata_var = user_strata_var
output$user_row_var = user_row_var
output$usr_create_cross_tab = usr_create_cross_tab
output$user_download_table = user_download_table
output$user_table_options = user_table_options
output$user_report_numeric = user_report_numeric
output$user_add_p_value = user_add_p_value
output$user_add_confidence_interval = user_add_confidence_interval
output$user_drop_missing_values = user_drop_missing_values
output$user_table_caption = user_table_caption
output$user_plot_options = user_plot_options
output$user_select_variable_on_x_axis = user_select_variable_on_x_axis
output$user_select_variable_on_y_axis = user_select_variable_on_y_axis
output$user_plot_title = user_plot_title
output$user_x_axis_label = user_x_axis_label
output$user_y_axis_label = user_y_axis_label
output$user_create = user_create
output$user_download = user_download
output$user_more_plot_options = user_more_plot_options
output$user_transform_to_doughnut = user_transform_to_doughnut
output$user_select_color_variable = user_select_color_variable
output$user_select_group_variable = user_select_group_variable
output$user_visual_orientation = user_visual_orientation
output$user_bar_width = user_bar_width
output$user_line_size = user_line_size
output$user_select_line_type = user_select_line_type
output$user_add_shapes = user_add_shapes
output$user_select_shape = user_select_shape
output$user_add_smooth = user_add_smooth
output$user_display_confidence_interval = user_display_confidence_interval
output$user_level_of_confidence_interval = user_level_of_confidence_interval
output$user_select_line_join = user_select_line_join
output$user_add_line_type = user_add_line_type
output$user_add_points = user_add_points
output$user_y_variable_summary_type = user_y_variable_summary_type
output$user_title_position = user_title_position
output$user_size_of_plot_title = user_size_of_plot_title
output$user_axis_title_size = user_axis_title_size
output$user_facet_title_size = user_facet_title_size
output$user_axis_text_size = user_axis_text_size
output$user_data_label_size = user_data_label_size
output$user_x_axis_text_angle = user_x_axis_text_angle
output$user_legend_title = user_legend_title
output$user_stacked = user_stacked
output$user_add_density = user_add_density
output$user_remove_histogram = user_remove_histogram
output$user_select_color_variable_single = user_select_color_variable_single
output$user_select_color_parlet = user_select_color_parlet
output$user_numeric_summary = user_numeric_summary
output$user_tab_more_out = user_tab_more_out
output$user_graph_more_out = user_tab_more_out
output$bivariate_header_label = bivariate_header_label
output$corrplot_header_label = corrplot_header_label
output$user_select_bivariate_single_color = user_select_bivariate_single_color
output$user_select_color_parlet_bivariate = user_select_color_parlet_bivariate
output$user_select_color_parlet_corrplot = user_select_color_parlet_corrplot
output$bivariate_plot_title = bivariate_plot_title
output$corrplot_title = corrplot_title
output$user_download_autoreport = user_download_autoreport
output$user_generatebivriate = user_generatebivriate
##### ---- Explore data actions ----------------------------------
explore_data_actions_server()
##### ---- Filter data --------------------------------------------
explore_data_filter_server()
explore_data_apply_filter_server()
explore_data_current_filter_server()
##### ---- Show/display -------------------------------------------------------
explore_show_data_server()
explore_data_reset_current_filter_server()
##### ---- Compute proportion of missing data ---------------------------
explore_missing_data_server()
##### ---- Select variables ---------------------------------------------
explore_data_select_variables_server()
explore_data_selected_variables_server()
##### ---- Update data -----------------------------------------------
explore_data_update_data_server()
#### ---- Transform variables -------------------------------------- ####
source("server/transform_data.R", local = TRUE)
##### ---- Select variables to transform ------------------------------------###
transform_data_select_variables_server()
##### ---- Change type -----------------------------------------------###
transform_data_change_type_server()
##### ---- Rename variables -----------------------------------------------###
transform_data_rename_variables_server()
##### ---- Recode/change value labels ---------------------------------------###
transform_data_quick_explore_recode_server()
##### ---- Handle missing data ---------------------------------------###
transform_data_create_missing_values_server()
##### ---- Identify outliers ---------------------------------------###
transform_data_identify_outliers_server()
##### ---- Handle missing values ---------------------------------------###
transform_data_handle_missing_values_server()
##### ---- Plot transform data ----------------------------------------------###
transform_data_quick_explore_plot_server()
##### ---- Plot missing data (LAZY-LOADED) --------------------------------###
.missing_loaded <- FALSE
observeEvent(input$dynamic_meinu_aphrc, {
if (!.missing_loaded && input$dynamic_meinu_aphrc %in% c("manageData", "transformData")) {
.missing_loaded <<- TRUE
transform_data_plot_missing_data_server()
}
}, ignoreInit = TRUE)
#### ---- Combine datasets with the existing one --------------------------------------####
source("server/combine_data.R", local = TRUE)
##### ---- List of internal data ------------------------------------------####
combine_data_list_datasets()
##### ---- Combine data options ------------------------------------------####
combine_data_type()
##### ---- Combine data mtch type ------------------------------------------####
combine_data_match_type()
##### ---- Combine data variables matched --------------------####
combine_data_variable_matching()
#### ----- Perform matching ---------------------------------####
combine_data_perform_variable_match()
##### ---- Combine data perform merging --------------------####
combine_data_perform_merging()
#### ---- Reset combine data --------------------------------####
combine_data_reset()
##### ---- Custom visualizations (LAZY-LOADED) ------------------ #####
.viz_loaded <- FALSE
observeEvent(input$dynamic_meinu_aphrc, {
if (!.viz_loaded && input$dynamic_meinu_aphrc %in% c("summarizeCustom", "visualizeData")) {
.viz_loaded <<- TRUE
source("server/user_defined_visualization.R", local = TRUE)
user_defined_server()
}
}, ignoreInit = TRUE)
### ------- OMOP ------------------------------------------ #####
#### ----- Cohort Constructor ---------#####
source("server/run_cohort_pipeline.R", local = TRUE)
run_cohort_pipeline()
#### ----- Feature Extraction ---------#####
source("server/feature_extraction_pipeline.R", local = TRUE)
feature_extraction_pipeline()
#### ---- Achilles Integration -------------------####
source("server/run_achilles.R", local = TRUE)
achilles_integration_server()
### ---- OMOP CDM Summaries---------------------------####
source("server/omop_summaries.R", local = TRUE)
omopVizServer()
### ---- Data Anonymization ---------------------------####
source("server/anon_server_module_quant.R", local = TRUE)
mod_quant_anon_server("quant_anon", rv_current = rv_current)
#### ---- Generate Research Questions --------------------------------------####
source("server/research_questions.R", local = TRUE)
generate_research_questions_choices()
##### ---- API Token ------------------ ####
generate_research_questions_api_token()
generate_research_questions_api_store()
#### ---- Addional prompts --------------- ####
generate_research_questions_additional()
#### ---- Generate insights using Gemini --------------- ####
generate_research_questions_gemini()
#### ---- Machine learning and AI --------------- ####
##### ----- Set ML/AI UI ------------------- ####
update_progress("Loading ML modules...")
source("server/setup_models.R", local=TRUE)
setup_models_ui()
##### ----- Preprocessing ------------------- ####
source("server/feature_engineering.R", local=TRUE)
#### Preprocessing ------------------------------------------- ####
feature_engineering_perform_preprocess_server()
#### ------ Missing value imputation -------------------------- ####
feature_engineering_recipe_server()
feature_engineering_impute_missing_server()
#### ----- Modelling framework --------------------------------- ####
source("server/modelling_framework.R", local=TRUE)
modelling_framework_choices()
#### ----- Model setup ----------------------------------------- ####
source("server/model_training_setup.R", local=TRUE)
model_training_setup_server()
#### ----- Caret models --------------------------------------- ####
source("server/model_training_caret_models.R", local=TRUE)
## LM/GLM
model_training_caret_models_ols_server()
## RF
model_training_caret_models_rf_server()
## GBM
model_training_caret_models_gbm_server()
## xgbTree
model_training_caret_models_xgbTree_server()
## xgbLinear
model_training_caret_models_xgbLinear_server()
## svmRadial
model_training_caret_models_svmRadial_server()
## svmLinear
model_training_caret_models_svmLinear_server()
## svmPoly
model_training_caret_models_svmPoly_server()
## glmnet
model_training_caret_models_glmnet_server()
## LASSO
model_training_caret_models_lasso_server()
## Ridge
model_training_caret_models_ridge_server()
## KNN
model_training_caret_models_knn_server()
## NNET
model_training_caret_models_nnet_server()
## TREEBAG
model_training_caret_models_treebag_server()
## avNNet
model_training_caret_models_avNNet_server()
## PLS
model_training_caret_models_pls_server()
## GAM
model_training_caret_models_gam_server()
## DT (RPART)
model_training_caret_models_rpart_server()
## mlpWeightDecayML (MLP)
model_training_caret_models_mlpWeightDecayML_server()
## Naive Bayes
model_training_caret_models_naive_bayes_server()
#### ----- Train all models ----------------------------------- ####
source("server/train_caret_models.R", local=TRUE)
model_training_caret_train_all_server()
#### ----- Compare trained models (LAZY-LOADED) --------------------- ####
.compare_loaded <- FALSE
observeEvent(input$dynamic_meinu_aphrc, {
if (!.compare_loaded && input$dynamic_meinu_aphrc %in% c("validateDeployModel", "trainModel")) {
.compare_loaded <<- TRUE
source("server/compare_trained_caret_models.R", local = TRUE)
model_training_caret_train_metrics_server()
}
}, ignoreInit = TRUE)
#### ----- Deploy trained models ------------------------------- ####
source("server/deploy_trained_caret_models.R", local=TRUE)
deploy_trained_caret_models()
#### ---- Predict using no-code models ------------------------ ####
source("server/predict_trained_caret_models.R", local=TRUE)
predict_trained_caret_models()
#### ---- PyCaret Integration (API) ----------------------------------------------------
# New ADD
rv_ml_ai <- rv_ml_ai %||% reactiveValues(target = NULL, outcome = NULL)
rv_current <- rv_current %||% reactiveValues(target = NULL)
deployment_server(id="deploy",rv_ml_ai=rv_ml_ai,rv_current = rv_current,api_base=api_base)
predict_pycaret_server("predict_pycaret", api_base , rv_current, rv_ml_ai)
# END NEW ADD
#### ---- Call current dataset for FastAPI ---------------------------------------------------
source("server/automl_server.R", local=TRUE)
automl_server("automl_module", rv_current, rv_ml_ai)
observe({
req(!is.null(rv_ml_ai$modelling_framework)) # Check if value exist
if (tolower(rv_ml_ai$modelling_framework) == "pycaret") {
output$automl_module_ui <- renderUI({
automl_ui("automl_module")
})
} else {
output$automl_module_ui <- renderUI({
h4("")
})
}
})
observeEvent(input$modelling_framework_choices, {
rv_ml_ai$framework <- tolower(input$modelling_framework_choices %||% "")
}, ignoreInit = FALSE)
#### ---- Deep Learning Server (LAZY-LOADED) ----- ###
.dl_loaded <- FALSE
observeEvent(input$dynamic_meinu_aphrc, {
if (!.dl_loaded && input$dynamic_meinu_aphrc %in% c("deeplearning", "cnndeep")) {
.dl_loaded <<- TRUE
source("server/deep_learning.R", local = TRUE)
deep_learning()
}
}, ignoreInit = TRUE)
#### ---- Reset various components --------------------------------------####
## Various components come before this
source("server/resets.R", local = TRUE)
##### ---- Reset on delete or language change ------------------- ####
reset_data_server()
#### ---- Activate required fields --------------------------------------####
iv$enable()
iv_url$enable()
iv_ml$enable()
update_progress("Ready!")
waiter::waiter_hide()
}, ignoreInit = FALSE)
waiter::waiter_hide()
}