Commit 61e6b1e0 authored by jbleher's avatar jbleher
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
Loading

Dockerfile

0 → 100644
+29 −0
Original line number Diff line number Diff line
# Base image https://hub.docker.com/u/rocker/
FROM rocker/shiny:latest

# system libraries of general use
## install debian packages
RUN apt-get update -qq && apt-get -y --no-install-recommends install \
    libxml2-dev \
    libcairo2-dev \
    libsqlite3-dev \
    libmariadbd-dev \
    libpq-dev \
    libssh2-1-dev \
    unixodbc-dev \
    libcurl4-openssl-dev \
    libssl-dev

## update system libraries
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get clean
USER root
# install renv & restore packages
RUN Rscript -e 'install.packages(c("renv","tidyverse","plotly"))'

# expose port
EXPOSE 3838

# run app on container start
CMD ["R", "-e", "shiny::runApp('/app', host = '0.0.0.0', port = 3838)"]

assets/.gitignore

0 → 100644
+1 −0
Original line number Diff line number Diff line
logs/
+33 −0
Original line number Diff line number Diff line
upstream shinyservice {
 server localhost:3838;
}



server {
 listen 80;
 #server_name localhost;
 location / {
   # This would be the directory where your React app's static files are stored at
   root /usr/share/nginx/html;
   try_files $uri /index.html;
 }

 location /CLT {
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-NginX-Proxy true;
   proxy_pass http://shinyservice;
   proxy_ssl_session_reuse off;
   proxy_set_header Host $http_host;
   proxy_cache_bypass $http_upgrade;
   proxy_redirect off;
 }
}


# 0. git clone <repo URL>
# 1. cd <repo>
# 2. Change IP Address in assets/config/nginx.conf
# 3. change folder in docker-compose to shiny app folder
# 4. docker-compose up -d
+0 −0

Empty file added.

+32 −0
Original line number Diff line number Diff line
get_my_sample <- function(nn,NN,theseed,correlated,pos_correlated){
    set.seed(theseed)
    # Draw nn observations from a standard normal distribution
    Sample_list <- lapply(1:NN,function(x) rnorm(nn))
    # Concatenate the lists to a data frame then cast the data.frame into a matrix
    samples_indep <- as.matrix(do.call("rbind",Sample_list))
    if(correlated){
        # Generate a random correlation matrix:
        # runif(nn^2)*2-1 generates nn² draws from the uniform distribution and
        # changes the support to -1 to 1 by multiplying by 2 and subtracting 1
        # One could also us another distribution it really doesn't matter for our purpose.
        # BB%*%BB will be the covariance variance matrix of the joint distribution of our realizations.
        # Nonetheless, if we would like to have only positive correlations then we would need to change the support
        # here to some positive interval (i.e. 0 to 1)
        if(!pos_correlated){
            BB <- matrix(runif(nn^2)*2-1, ncol=nn)
        }else{
            # Comment this line in if you would like to see only positive correlations
            BB <- matrix(runif(nn^2), ncol=nn)
        }
        Sigma <- t(BB)%*%BB
        # In any case, we need to standardise the variables so that the variance is between 0 and 1
        CC <- BB/matrix(sqrt(diag(Sigma)),nn,nn,byrow = TRUE)
        Sigma_std <- t(CC)%*%CC
        
        # Transform the iid standard normally observations into correlated normal distributions
        samples_corr <- (samples_indep%*%CC)
        
        return(samples_corr)
    }
    return(samples_indep)
}