Spaces:
Runtime error

cynthia-hg commited on
Commit
b381cc9
·
verified ·
1 Parent(s): e0a9bb2

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. Dockerfile +16 -0
  3. app.R +101 -0
  4. final_rf_model.rds +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ final_rf_model.rds filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM rocker/shiny:4.3.1
2
+
3
+ # Install required R packages
4
+ RUN R -e "install.packages(c('randomForest', 'shiny'), repos='https://cloud.r-project.org')"
5
+
6
+ # Copy app files
7
+ COPY app.R /srv/shiny-server/app.R
8
+ COPY final_rf_model.rds /srv/shiny-server/final_rf_model.rds
9
+
10
+ # Set permissions
11
+ RUN chown -R shiny:shiny /srv/shiny-server
12
+
13
+ # Expose the Shiny port
14
+ EXPOSE 3838
15
+
16
+ CMD ["/usr/bin/shiny-server"]
app.R ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(shiny)
2
+ library(randomForest)
3
+
4
+ model <- readRDS("final_rf_model.rds")
5
+
6
+ ui <- fluidPage(
7
+ titlePanel("T2D Risk Prediction App"),
8
+ sidebarLayout(
9
+ sidebarPanel(
10
+ numericInput("Age", "Age", 55),
11
+ numericInput("Weight", "Weight (kg)", 70),
12
+ numericInput("BMI", "BMI", 25),
13
+ numericInput("Height", "Height (cm)", 165),
14
+ numericInput("Triglyceride", "Triglyceride", 150),
15
+ numericInput("Total.Cholesterol", "Total Cholesterol", 200),
16
+ numericInput("HDL", "HDL", 50),
17
+ numericInput("LDL", "LDL", 120),
18
+ selectInput("Gender", "Gender", choices = c("Female", "Male")),
19
+ selectInput("CVD", "CVD", choices = c("No", "Yes")),
20
+ selectInput("Hyperlipidemia", "Hyperlipidemia", choices = c("No", "Yes")),
21
+ selectInput("Hypertension", "Hypertension", choices = c("No", "Yes")),
22
+ selectInput("Fx.Hypertension", "Fx.Hypertension", choices = c("No", "Yes")),
23
+ selectInput("Fx.T2D", "Fx.T2D", choices = c("No", "Yes")),
24
+ selectInput("Fx.Hyperlipidemia", "Fx.Hyperlipidemia", choices = c("No", "Yes")),
25
+ selectInput("Smoking.", "Smoking.", choices = c("No", "Yes")),
26
+ selectInput("Fx.CVD", "Fx.CVD", choices = c("No", "Yes")),
27
+ selectInput("rs12137794", "rs12137794", choices = c("CC", "TC", "TT")),
28
+ selectInput("rs587404", "rs587404", choices = c("AA", "AG", "GG")),
29
+ selectInput("rs1260326", "rs1260326", choices = c("CC", "CT", "TT")),
30
+ selectInput("rs2943641", "rs2943641", choices = c("CC", "TC", "TT")),
31
+ selectInput("rs2943645", "rs2943645", choices = c("CC", "CT", "TT")),
32
+ selectInput("rs2972143", "rs2972143", choices = c("AA", "AG", "GG")),
33
+ selectInput("rs2877716", "rs2877716", choices = c("CC", "TC", "TT")),
34
+ selectInput("rs10804976", "rs10804976", choices = c("GG", "GT", "TT")),
35
+ selectInput("rs7756992", "rs7756992", choices = c("AA", "GA", "GG")),
36
+ selectInput("rs3130501", "rs3130501", choices = c("AA", "AG", "GG")),
37
+ selectInput("rs3132946", "rs3132946", choices = c("AA", "AG", "GG")),
38
+ selectInput("rs2395163", "rs2395163", choices = c("CC", "CT", "TT")),
39
+ selectInput("rs2395182", "rs2395182", choices = c("GG", "GT", "TT")),
40
+ selectInput("rs6903608", "rs6903608", choices = c("CC", "TC", "TT")),
41
+ selectInput("rs2395185", "rs2395185", choices = c("GG", "TG", "TT")),
42
+ selectInput("rs9275595", "rs9275595", choices = c("CC", "CT", "TT")),
43
+ selectInput("rs987237", "rs987237", choices = c("AA", "GA", "GG")),
44
+ selectInput("rs9388489", "rs9388489", choices = c("AA", "AG", "GG")),
45
+ selectInput("rs4273712", "rs4273712", choices = c("AA", "GA", "GG")),
46
+ selectInput("rs2246012", "rs2246012", choices = c("CC", "CT", "TT")),
47
+ selectInput("rs10244051", "rs10244051", choices = c("GG", "TG", "TT")),
48
+ selectInput("rs4607517", "rs4607517", choices = c("AA", "AG", "GG")),
49
+ selectInput("rs13266634", "rs13266634", choices = c("CC", "TC", "TT")),
50
+ selectInput("rs4977756", "rs4977756", choices = c("AA", "GA", "GG")),
51
+ selectInput("rs10965243", "rs10965243", choices = c("AA", "GA", "GG")),
52
+ selectInput("rs11257655", "rs11257655", choices = c("CC", "TC", "TT")),
53
+ selectInput("rs10906115", "rs10906115", choices = c("AA", "GA", "GG")),
54
+ selectInput("rs6583826", "rs6583826", choices = c("AA", "GA", "GG")),
55
+ selectInput("rs5015480", "rs5015480", choices = c("CC", "TC", "TT")),
56
+ selectInput("rs7923837", "rs7923837", choices = c("AA", "AG", "GG")),
57
+ selectInput("rs7903146", "rs7903146", choices = c("CC", "TC", "TT")),
58
+ selectInput("rs5215", "rs5215", choices = c("CC", "CT", "TT")),
59
+ selectInput("rs11555762", "rs11555762", choices = c("CC", "TC", "TT")),
60
+ selectInput("rs1387153", "rs1387153", choices = c("CC", "TC", "TT")),
61
+ selectInput("rs2166706", "rs2166706", choices = c("CC", "CT", "TT")),
62
+ selectInput("rs8756", "rs8756", choices = c("AA", "CA", "CC")),
63
+ selectInput("rs3764002", "rs3764002", choices = c("CC", "TC", "TT")),
64
+ selectInput("rs10146997", "rs10146997", choices = c("AA", "GA", "GG")),
65
+ selectInput("rs4886707", "rs4886707", choices = c("CC", "TC", "TT")),
66
+ selectInput("rs7177055", "rs7177055", choices = c("AA", "GA", "GG")),
67
+ selectInput("rs8042680", "rs8042680", choices = c("AA", "AC", "CC")),
68
+ selectInput("rs8050136", "rs8050136", choices = c("AA", "AC", "CC")),
69
+ selectInput("rs7202877", "rs7202877", choices = c("GG", "GT", "TT")),
70
+ selectInput("rs13342692", "rs13342692", choices = c("CC", "CT", "TT")),
71
+ selectInput("rs12970134", "rs12970134", choices = c("AA", "AG", "GG")),
72
+ selectInput("rs2075650", "rs2075650", choices = c("AA", "GA", "GG")),
73
+ actionButton("predict", "Predict T2D Risk")
74
+ ),
75
+ mainPanel(
76
+ h3("Prediction Result"),
77
+ verbatimTextOutput("result")
78
+ )
79
+ )
80
+ )
81
+
82
+ server <- function(input, output) {
83
+ observeEvent(input$predict, {
84
+ input_data <- as.data.frame(as.list(input), stringsAsFactors = FALSE)
85
+
86
+ num_vars <- c("Age", "Weight", "BMI", "Height", "Triglyceride", "Total.Cholesterol", "HDL", "LDL")
87
+ input_data[num_vars] <- lapply(input_data[num_vars], as.numeric)
88
+
89
+ factor_vars <- c("Gender", "CVD", "Hyperlipidemia", "Hypertension", "Fx.Hypertension",
90
+ "Fx.T2D", "Fx.Hyperlipidemia", "Smoking.", "Fx.CVD")
91
+ input_data[factor_vars] <- lapply(input_data[factor_vars], as.factor)
92
+
93
+ prediction <- predict(model, input_data, type = "response")
94
+
95
+ output$result <- renderPrint({
96
+ paste("Predicted T2D Risk (Yes = 1 / No = 0):", prediction)
97
+ })
98
+ })
99
+ }
100
+
101
+ shinyApp(ui = ui, server = server, options = list(host = "0.0.0.0", port = 7860))
final_rf_model.rds ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a9e9c27d46fb1d4680646b1d60af9e8742a229acb8869187e786f518969bf226
3
+ size 1199593