-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
52 lines (48 loc) · 2.44 KB
/
global.R
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
# for environments needing user-space packages
if(dir.exists('R-lib')) .libPaths(c(normalizePath('R-lib'),.libPaths()));
# # If this is a git repo, construct the git link
# githash <- system('git rev-parse HEAD',intern=T);
# gitlink <- if(!is.null(attributes(githash))){
# 'https://github.com/bokov/clinical_opendashboard'} else {
# paste0('https://github.com/bokov/clinical_opendashboard/tree/',githash)};
# ---- Enforce version specific dependencies ----
# The data.table update has to be done before plotly is loaded otherwise plotly
# errors when trying to render numeric (scatterplot) variables
.packagedebug <- try(if(R.version$major>=3 && R.version$minor >= 6 &&
packageVersion('data.table')<'1.11.2'){
install.packages('data.table',repos='https://cloud.r-project.org')});
if(is(.packagedebug,'try-error')) warning(.packagedebug);
library(readr); library(shinyTree); library(git2r);
# git link
gitlink <- if(!is(githash <- try(sha(repository_head())),'try-error')){
paste0('https://github.com/bokov/clinical_opendashboard/tree/',githash);
} else 'https://github.com/bokov/clinical_opendashboard';
#gitlink <- 'https://github.com/bokov/clinical_opendashboard';
# selected prefixes and concept codes
# TODO: consider dynamically creating demogcodes.csv from the data if it doesn't
# exist.
# TODO: What would happen if there was a row in demogcodes.csv with PREFIX='ALL'
# instead of being added on at runtime? Would this be a cleaner solution?
demogcodes <- if(file.exists('demogcodes.csv')){
read_csv('demogcodes.csv')} else {read_csv('demogcodes_demo.csv')};
# Prepending 'INACT' to the PREFIX column will cause that code to be
# hidden.
demogcodes <- subset(demogcodes,!grepl('^INACT',PREFIX));
# prefixes whose variables should be rendered as scatter-plots
prefixpoints <- c(subset(demogcodes,is.na(CCD))$PREFIX,'ALL');
# demogcodes should include the following columns: 'PREFIX','Category','CCD'
# PREFIX and CCD are the same as used by ChinoType. Category is a human-readable
# version of PREFIX.
selBasicChoices <- with(unique(demogcodes[,c('PREFIX','Category')])
,c(grep('TOTAL',inv=T,val=T,setNames(PREFIX,Category))
,c(`All Codes`='ALL')));
# slider defaults
slidevals <- list(N=300,OR=1.5
#,Chi=200
,Chi=0.05
);
# UI text
source('uitext.R');
# to override various stuff
if(file.exists('project_uitext.R')) source('project_uitext.R');
c()