# Run inside the NAS rocker/shiny container, as root.
# This is the Shiny application runtime; Seurat/qs/VIPER are not required.
options(timeout = 1200)
repos <- getOption('repos')
if (is.null(repos) || identical(unname(repos['CRAN']), '@CRAN@') || is.na(repos['CRAN'])) {
  repos <- c(CRAN = 'https://cloud.r-project.org')
}
options(repos = repos, Ncpus = 2L)
required <- c('shiny', 'shinyhelper', 'data.table', 'Matrix', 'DT',
              'magrittr', 'ggplot2', 'ggrepel', 'hdf5r', 'ggdendro',
              'gridExtra', 'ggpubr')
missing <- required[!vapply(required, requireNamespace, logical(1), quietly = TRUE)]
if (length(missing)) install.packages(missing)
failed <- required[!vapply(required, requireNamespace, logical(1), quietly = TRUE)]
if (length(failed)) stop('Packages still missing: ', paste(failed, collapse = ', '))
print(data.frame(package = required,
                 version = vapply(required, function(p) as.character(packageVersion(p)), character(1))))
cat('\nShinyCell2 application runtime is ready.\n')
