Skip to content

Commit

Permalink
Merge pull request #1305 from bigomics/upload-fail-catch
Browse files Browse the repository at this point in the history
Catch upload data error
  • Loading branch information
ivokwee authored Dec 12, 2024
2 parents 857735e + d007a70 commit d647771
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 24 deletions.
34 changes: 20 additions & 14 deletions components/board.upload/R/upload_module_preview_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,27 @@ upload_table_preview_contrasts_server <- function(
return()
}

ct <- playbase::read.as_matrix(input$contrasts_csv$datapath)

## IK: should we do contrasts.convertToLabelMatrix here
## already? to allow for short/old formats?
## samples <- checked_samples()$SAMPLES
samples <- uploaded$samples.csv
new.ct <- try(playbase::contrasts.convertToLabelMatrix(
contrasts = ct, samples = samples
))
if (!"try-error" %in% class(new.ct)) {
ct <- new.ct
ct <- tryCatch({
playbase::read.as_matrix(input$contrasts_csv$datapath)
}, error = function(w) {NULL})
if (is.null(ct)) {
data_error_modal(
path = input$contrasts_csv$datapath,
data_type = "contrasts"
)
} else {
## IK: should we do contrasts.convertToLabelMatrix here
## already? to allow for short/old formats?
## samples <- checked_samples()$SAMPLES
samples <- uploaded$samples.csv
new.ct <- try(playbase::contrasts.convertToLabelMatrix(
contrasts = ct, samples = samples
))
if (!"try-error" %in% class(new.ct)) {
ct <- new.ct
}
uploaded$contrasts.csv <- ct
}


uploaded$contrasts.csv <- ct
})

observeEvent(input$remove_contrasts, {
Expand Down
45 changes: 36 additions & 9 deletions components/board.upload/R/upload_module_preview_counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,51 @@ upload_table_preview_counts_server <- function(

sel <- grep("count|expression|abundance", tolower(input$counts_csv$name))
if (length(sel)) {
df <- playbase::read_counts(input$counts_csv$datapath[sel[1]])
uploaded$counts.csv <- df
df <- tryCatch({
playbase::read_counts(input$counts_csv$datapath[sel[1]])
}, error = function(w) {NULL})
if (is.null(df)) {
data_error_modal(
path = input$counts_csv$datapath[sel[1]],
data_type = "counts"
)
} else {
uploaded$counts.csv <- df

## if counts file contains annotation
af <- playbase::read_annot(input$counts_csv$datapath[sel[1]])
uploaded$annot.csv <- af
# if counts file contains annotation
af <- playbase::read_annot(input$counts_csv$datapath[sel[1]])
uploaded$annot.csv <- af
}
}

sel <- grep("samples", tolower(input$counts_csv$name))
if (length(sel)) {
df <- playbase::read_samples(input$counts_csv$datapath[sel[1]])
uploaded$samples.csv <- df
df <- tryCatch({
playbase::read_samples(input$counts_csv$datapath[sel[1]])
}, error = function(w) {NULL})
if (is.null(df)) {
data_error_modal(
path = input$counts_csv$datapath[sel[1]],
data_type = "samples"
)
} else {
uploaded$samples.csv <- df
}
}

sel <- grep("contrast|comparison", tolower(input$counts_csv$name))
if (length(sel)) {
df <- playbase::read_contrasts(input$counts_csv$datapath[sel[1]])
uploaded$contrasts.csv <- df
df <- tryCatch({
playbase::read_contrasts(input$counts_csv$datapath[sel[1]])
}, error = function(w) {NULL})
if (is.null(df)) {
data_error_modal(
path = input$counts_csv$datapath[sel[1]],
data_type = "contrasts"
)
} else {
uploaded$contrasts.csv <- df
}
}

sel <- grep("params.RData", input$counts_csv$name)
Expand Down
12 changes: 11 additions & 1 deletion components/board.upload/R/upload_module_preview_samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,17 @@ upload_table_preview_samples_server <- function(
overwrite = TRUE
)

uploaded$samples.csv <- playbase::read.as_matrix(input$samples_csv$datapath)
df <- tryCatch({
playbase::read.as_matrix(input$samples_csv$datapath)
}, error = function(w) {NULL})
if (is.null(df)) {
data_error_modal(
path = input$samples_csv$datapath,
data_type = "samples"
)
} else {
uploaded$samples.csv <- df
}
})

observeEvent(input$remove_samples, {
Expand Down
37 changes: 37 additions & 0 deletions components/board.upload/R/upload_module_utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
data_error_modal <- function(path, data_type) {
con <- file(path, "rb")
text_raw <- readBin(con, "raw", n = 1000)
close(con)
is_bin <- tryCatch({
paste(rawToChar(text_raw), collapse = "")
}, error = function(w) {NULL})
if (!is.null(is_bin)) {
shinyalert::shinyalert(
title = "Upload error",
text = shiny::tagList(
shiny::HTML(glue::glue("There seems to be an issue with your data file. It could be the data has been wrongly exported, <u><b><a href='https://omicsplayground.readthedocs.io/en/latest/dataprep/{data_type}/' target='_blank'>here</a></b></u> you can find the file specification documentation, and <u><b><a href='https://raw.githubusercontent.com/bigomics/playbase/refs/heads/main/inst/extdata/{data_type}.csv' target='_blank'>here</a></b></u> you can find a correct data file. <br><br> The 10 first lines of the input file are the following:")),
shiny::HTML("<br><br>"),
shiny::tags$pre(
paste(readLines(path, n = 10), collapse = "\n")
),
shiny::HTML("We suggest visualizing on your computer the data using a plain text editor (rather than Excel) to check on your end the file is correct.")
),
html = TRUE,
size = "l",
type = "error",
className = "left-align"
)
} else {
shinyalert::shinyalert(
title = "Upload error",
text = shiny::tagList(
shiny::HTML(glue::glue("There seems to be an issue with your data file. We detected it is a binary file rather than a plain text csv file. It could be the data has been wrongly exported. You can find the file specification documentation <u><b><a href='https://omicsplayground.readthedocs.io/en/latest/dataprep/{data_type}/' target='_blank'>here</a></b></u>.<br><br>")),
shiny::HTML("We suggest visualizing on your computer the data using a plain text editor (rather than Excel) to check on your end the file is correct.")
),
html = TRUE,
size = "l",
type = "error",
className = "left-align"
)
}
}
3 changes: 3 additions & 0 deletions scss/components/_shinyalert.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.left-align {
text-align: left !important;
}
1 change: 1 addition & 0 deletions scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
@import "components/carousel.scss";
@import "components/tick.scss";
@import "components/navbar.scss";
@import "components/shinyalert.scss";
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d647771

Please sign in to comment.