Skip to content

Commit 5123683

Browse files
fix tests and slack error
1 parent 6ac51de commit 5123683

File tree

8 files changed

+55
-29
lines changed

8 files changed

+55
-29
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: dseqr
22
Type: Package
33
Title: GUI to Explore Single-Cell and Bulk RNA-Seq from Fastq to Pathways and Perturbations
4-
Version: 0.36.0
4+
Version: 0.37.0
55
Authors@R: person("Alex", "Pickering", email="[email protected]", role=c("cre", "aut"))
66
BugReports: https://github.com/hms-dbmi/dseqr/issues
77
URL: https://github.com/hms-dbmi/dseqr

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export(run_dseqr)
2828
export(run_kb_scseq)
2929
export(scPage)
3030
export(scPageUI)
31+
export(send_slack_error)
3132
export(theme_dimgray)
3233
export(theme_no_xaxis)
3334
export(theme_no_yaxis)

R/recover_error.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11

2-
send_slack_error <- function(project) {
2+
#' Send shiny errors to slack
3+
#'
4+
#' @param project The project that the error originated from
5+
#' @param user The user that the error originated from
6+
#'
7+
#' @return Generates an alert in browser
8+
#' @export
9+
#'
10+
send_slack_error <- function(project, user) {
311

4-
user <- Sys.getenv('SHINYPROXY_USERNAME', 'localhost')
512
project <- ifelse(project == user, 'private', project)
613
error <- recover_error()
714
slack <- readRDS(system.file('extdata/slack.rds', package = 'dseqr'))

R/run_dseqr.R

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#'
33
#' Run dseqr application to explore single-cell and bulk RNA-seq datasets.
44
#'
5-
#' @param user_name Name of user folder in \code{data_dir}. Will be created if doesn't exist.
6-
#' @param data_dir Directory containing user folders. By default also will contain folders
5+
#' @param app_name Name of user folder in \code{data_dir}. Will be created if doesn't exist.
6+
#' @param data_dir Directory containing app folders. By default also will contain folders
77
#' \code{.pert_query_dir}, \code{.pert_signature_dir}, and \code{.indices_dir}.
88
#' @param tabs Character vector of tabs to include in order desired. Must be subset of 'Single Cell', 'Bulk Data', and 'Drugs'.
99
#' @param pert_query_dir Path to directory where pert query results (using CMAP02/L1000 as query signature) will be downloaded as requested.
@@ -61,13 +61,9 @@ run_dseqr <- function(app_name,
6161
data_dir <- '/srv/dseqr'
6262
}
6363

64-
6564
# gather options
6665
opts <- list()
6766

68-
# on remote: send errors to slack
69-
if (!is_local) opts$shiny.error <- function() send_slack_error(app_name)
70-
7167
# allow up to 30GB uploads
7268
opts$shiny.maxRequestSize <- 30*1024*1024^2
7369

@@ -91,14 +87,6 @@ run_dseqr <- function(app_name,
9187

9288
if (missing(data_dir)) stop('data_dir not specified.')
9389

94-
# user_dir <- file.path(data_dir, app_name)
95-
# if (!dir_exists(user_dir)) init_dseqr(app_name, data_dir)
96-
97-
# ensure various directories exist
98-
# duplicated in server.R for tests
99-
app_dirs <- c(pert_query_dir, pert_signature_dir, indices_dir, tx2gene_dir, gs_dir)
100-
for (dir in app_dirs) dir.create(dir, showWarnings = FALSE)
101-
10290
# pass arguments to app through options then run
10391
shiny::shinyOptions(
10492
data_dir = normalizePath(data_dir),

inst/app/server.R

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ get_num_bulk_datasets <- function(project, user_dir) {
6666

6767
server <- function(input, output, session) {
6868

69+
6970
# get arguments from calling function
7071
# defaults for testing
7172
# shiny::shinyOptions don't make it through
7273

7374
# base directory contains data_dir folder
7475
app_name <- getShinyOption('app_name', 'test_app')
75-
data_dir <- getShinyOption('data_dir', 'tests/testthat/test_data_dir/')
76+
data_dir <- getShinyOption('data_dir', 'tests/testthat/test_data_dir')
7677

7778
# path where pert queries will be stored
7879
pert_query_dir <- getShinyOption('pert_query_dir', file.path(data_dir, '.pert_query_dir'))
@@ -92,11 +93,26 @@ server <- function(input, output, session) {
9293
is_example <- getShinyOption('is_example', FALSE)
9394
is_local <- getShinyOption('is_local', TRUE)
9495

96+
# reset testing data
97+
if (isTRUE(getOption('shiny.testmode'))) {
98+
unlink(data_dir, recursive = TRUE)
99+
dir.create(data_dir, recursive = TRUE)
100+
}
101+
95102
# ensure various directories exist
96-
# duplicated here and in run_dseqr for tests
97103
app_dirs <- c(pert_query_dir, pert_signature_dir, indices_dir, tx2gene_dir, gs_dir)
98104
for (dir in app_dirs) dir.create(dir, showWarnings = FALSE)
99105

106+
# on remote: send errors to slack
107+
if (!is_local) {
108+
options(shiny.error = function() {
109+
observe({
110+
user_name <- user_name()
111+
send_slack_error(app_name, user_name)
112+
})
113+
})
114+
}
115+
100116

101117
# hide tour button for docs page
102118
observe(shinyjs::toggleClass('start_tour', 'invisible', condition = input$tab == 'Docs'))
@@ -106,19 +122,13 @@ server <- function(input, output, session) {
106122

107123
# app_name is 'private'
108124
user_name <- session$request$HTTP_X_SP_USERID
109-
print('user_name!!!!')
110-
print(user_name)
111125
return(user_name)
112126
})
113127

114128
user_dir <- reactive({
115129
user_name <- user_name()
116130
user_dir <- file.path(data_dir, user_name)
117131

118-
# reset testing data
119-
if (isTRUE(getOption('shiny.testmode')))
120-
unlink(data_dir, recursive = TRUE)
121-
122132
if (!dir_exists(user_dir))
123133
init_dseqr(user_name, data_dir)
124134

inst/app/tests/testthat/test-shinytest2.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ test_that("{shinytest2} recording: Single-Cell Tab", {
4646
load_timeout = timeout)
4747
)
4848

49-
list_files <- function()
49+
list_files <- function() {
5050
file.path(data_dir, list.files(data_dir, recursive = TRUE, all.files = TRUE, include.dirs = TRUE))
51+
}
5152

5253
# created expected files/folders
5354
init_files <- list_files()

man/run_dseqr.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/send_slack_error.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)