transfer from old repo

This commit is contained in:
Andreas Gammelgaard Damsbo 2026-08-19 09:27:27 +02:00
commit 277e2b8cf3
No known key found for this signature in database
1111 changed files with 83736 additions and 0 deletions

View file

@ -0,0 +1,9 @@
name: index_app
title:
username:
account: cognitiveindex
server: shinyapps.io
hostUrl: https://api.shinyapps.io/v1
appId: 6803928
bundleId: 8182645
url: https://cognitiveindex.shinyapps.io/index_app/

View file

@ -0,0 +1,24 @@
# Samlpe data from data base
source("https://raw.githubusercontent.com/agdamsbo/ENIGMAtrial_R/main/src/redcap_api_export_short.R")
df<-redcap_api_export_short(id= c(40:45),
instruments= "rbans",
event= "3_months_arm_1") %>%
select(c("record_id",ends_with(c("_version","_age","_rs")))) %>%
na.omit()|>
rbind(redcap_api_export_short(id= c(10:15),
instruments= "rbans",
event= "12_months_arm_1") %>%
select(c("record_id",ends_with(c("_version","_age","_rs")))) %>%
na.omit())
colnames(df)<-c("record_id","ab","age","imm","vis","ver","att","del")
## New index numbers
df$record_id<-1:nrow(df)
## Age is changed for obscurity
df$age<-sample(-2:2,nrow(df),TRUE)+df$age
write.csv(df, "sample.csv", row.names = FALSE)

13
apps/Index app/sample.csv Normal file
View file

@ -0,0 +1,13 @@
"record_id","ab","age","imm","vis","ver","att","del"
1,1,67,26,31,24,42,38
2,1,69,34,31,27,40,34
3,1,63,43,35,29,46,38
4,1,66,45,37,30,54,40
5,1,66,44,34,33,54,44
6,1,83,39,34,23,37,31
7,2,71,49,37,24,52,42
8,2,81,33,30,39,47,42
9,2,61,50,38,36,52,56
10,2,88,32,20,26,13,30
11,2,73,36,28,22,34,33
12,2,89,22,30,21,29,30
1 record_id ab age imm vis ver att del
2 1 1 67 26 31 24 42 38
3 2 1 69 34 31 27 40 34
4 3 1 63 43 35 29 46 38
5 4 1 66 45 37 30 54 40
6 5 1 66 44 34 33 54 44
7 6 1 83 39 34 23 37 31
8 7 2 71 49 37 24 52 42
9 8 2 81 33 30 39 47 42
10 9 2 61 50 38 36 52 56
11 10 2 88 32 20 26 13 30
12 11 2 73 36 28 22 34 33
13 12 2 89 22 30 21 29 30

104
apps/Index app/server.R Normal file
View file

@ -0,0 +1,104 @@
server <- function(input, output, session) {
library(dplyr)
library(ggplot2)
library(tidyr)
source("https://raw.githubusercontent.com/agdamsbo/ENIGMAtrial_R/main/src/plot_index.R")
source("https://raw.githubusercontent.com/agdamsbo/ENIGMAtrial_R/main/src/index_from_raw.R")
dat<-reactive({
df<-data.frame(record_id="1",
ab=input$version,
age=input$age,
imm=input$rs1,
vis=input$rs2,
ver=input$rs3,
att=input$rs4,
del=input$rs5,
stringsAsFactors = FALSE)
return(df)
})
dat_u<-reactive({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
req(input$file1)
df <- read.csv(input$file1$datapath,
header = input$header,
sep = input$sep,
quote = input$quote)
return(df)
})
dat_f<-reactive({
if (input$type==1){
return(dat())}
if (input$type==2){
return(head(dat_u(),10))}
})
index_p <- reactive({ df<-index_from_raw(ds=dat_f(),
indx=read.csv("https://raw.githubusercontent.com/agdamsbo/ENIGMAtrial_R/main/data/index.csv"),
version = dat_f()$ab,
age = dat_f()$age,
raw_columns=c("imm","vis","ver","att","del"))
colnames(df)<-c("id",
"a_is",
"b_is",
"c_is",
"d_is",
"e_is",
"i_is",
"a_ci",
"b_ci",
"c_ci",
"d_ci",
"e_ci",
"i_ci",
"a_per",
"b_per",
"c_per",
"d_per",
"e_per",
"i_per")
return(df)
})
output$ndx.tbl <- renderTable({
index_p()|>
select("id",contains("_is"))
})
output$per.tbl <- renderTable({
index_p()|>
select("id",contains("_per"))
})
output$ndx.plt<-renderPlot({
plot_index(index_p(),sub_plot = "_is")
})
output$per.plt<-renderPlot({
plot_index(index_p(),sub_plot = "_per")
})
# Downloadable csv of selected dataset ----
output$downloadData <- downloadHandler(
filename = "index_lookup.csv",
content = function(file) {
write.csv(index_p(), file, row.names = FALSE)
}
)
}

View file

@ -0,0 +1,18 @@
df<-data.frame(record_id="1",
imm=35,
vis=35,
ver=35,
att=35,
del=35,
stringsAsFactors = FALSE)
source("https://raw.githubusercontent.com/agdamsbo/ENIGMAtrial_R/main/src/index_from_raw.R")
df_c<-index_from_raw(ds=df,
indx=read.csv("https://raw.githubusercontent.com/agdamsbo/ENIGMAtrial_R/main/data/index.csv"),
version = "1",
age = 60,
raw_columns=c("imm","vis","ver","att","del"),
mani=TRUE)
plot_index(ds=df_c,id="id",sub_plot = "_is")

152
apps/Index app/ui.R Normal file
View file

@ -0,0 +1,152 @@
library(shiny)
library(ggplot2)
ui <- fluidPage(
## -----------------------------------------------------------------------------
## Application title
## -----------------------------------------------------------------------------
titlePanel("Calculating cognitive index scores in multidimensional testing.",
windowTitle = "Cognitive test index calculator"),
h5("Please note this calculator is only meant as a proof of concept for educational purposes,
and the author will take no responsibility for the results of the calculator.
Uploaded data is not kept, but please, do not upload any sensitive data."),
## -----------------------------------------------------------------------------
## Side panel
## -----------------------------------------------------------------------------
sidebarPanel(
h4("Test resultsData format"),
radioButtons(inputId = "type",
label = "Data type",
inline = FALSE,
choiceNames=c("Single entry",
"File upload (10 records)"),
choiceValues=c(1,2)),
# Horizontal line ----
tags$hr(),
## -----------------------------------------------------------------------------
## Single entry
## -----------------------------------------------------------------------------
conditionalPanel(condition = "input.type==1",
numericInput(inputId = "age",
label = "Age",
value=60),
radioButtons(inputId = "version",
label = "Test version (A/B)",
inline = FALSE,
choiceNames=c("A",
"B"),
choiceValues=c(1,2)),
numericInput(inputId = "rs1",
label = "Immediate memory",
value=35),
numericInput(inputId = "rs2",
label = "Visuospatial functions",
value=35),
numericInput(inputId = "rs3",
label = "Verbal functions",
value=30),
numericInput(inputId = "rs4",
label = "Attention",
value=35),
numericInput(inputId = "rs5",
label = "Delayed memory",
value=40)
),
## -----------------------------------------------------------------------------
## File upload
## -----------------------------------------------------------------------------
conditionalPanel(condition = "input.type==2",
# Input: Select a file ----
fileInput("file1", "Choose CSV File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
h6("Columns: record_id, ab, age, imm, vis, ver, att, del."),
# Horizontal line ----
tags$hr(),
# Input: Checkbox if file has header ----
checkboxInput("header", "Header", TRUE),
# Input: Select separator ----
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
# Input: Select quotes ----
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
),
## -----------------------------------------------------------------------------
## Download output
## -----------------------------------------------------------------------------
# Horizontal line ----
tags$hr(),
h4("Download results"),
# Button
downloadButton("downloadData", "Download")
),
mainPanel(
tabsetPanel(
## -----------------------------------------------------------------------------
## Summary tab
## -----------------------------------------------------------------------------
tabPanel("Summary",
h3("Index Scores"),
htmlOutput("ndx.tbl", container = span),
h3("Percentiles"),
htmlOutput("per.tbl", container = span)
),
## -----------------------------------------------------------------------------
## Plots tab
## -----------------------------------------------------------------------------
tabPanel("Plots",
h3("Index Scores"),
plotOutput("ndx.plt"),
h3("Percentiles"),
plotOutput("per.plt")
)
)
)
)