Skip to content

Commit bff70ee

Browse files
committed
shiny 1.3.1
1 parent 033355c commit bff70ee

6 files changed

Lines changed: 391 additions & 88 deletions

File tree

‎DESCRIPTION‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Imports:
5353
tibble,
5454
shiny,
5555
bslib,
56+
htmltools,
5657
GEOquery,
5758
DT,
5859
base64enc,

‎R/geo_import_module.R‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,21 @@ import_geo_data <- function(gse_accession,
917917
return(result)
918918
}
919919

920+
# The Shiny import/preprocessing pipeline (gene-ID detection, TMM/DESeq2 VST
921+
# normalisation) is built for bulk RNA-seq and is not valid for microarray
922+
# data. Microarray support isn't implemented in the app yet, so block it
923+
# here rather than silently running the RNA-seq pipeline on it.
924+
if (assay_info$type == "microarray") {
925+
result$status <- "excluded"
926+
result$messages <- c(msgs, paste0(
927+
"⛔ ", gse_accession, " is a microarray dataset (", assay_info$reason, "). ",
928+
"Microarray import is not yet supported in the markeR Shiny app (planned for a ",
929+
"future version). You can still analyse microarray data with the markeR R ",
930+
"package directly - preprocess your probe-level matrix to gene symbols yourself ",
931+
"(e.g. with limma) and pass it to markeR's analysis functions in R."))
932+
return(result)
933+
}
934+
920935
# ── 3. Try built-in expression matrix (Series Matrix) ─────────────────────
921936
.prog(0.30, "Checking Series Matrix expression data…")
922937
for (obj in geo_objs) {

‎R/markeR_preprocessing.R‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,19 @@
576576
if (mean(grepl("^ENS[A-Z]+[0-9]", s)) > 0.5) return("ensembl_other")
577577
if (mean(grepl("^(NM_|NR_|XM_|XR_)[0-9]", s)) > 0.5) return("refseq")
578578
if (mean(grepl("^[0-9]+$", s)) > 0.5) return("entrez")
579+
# Microarray probe IDs (Affymetrix, Illumina, Agilent, ...). These are
580+
# platform-specific and are NOT gene identifiers - without matching them
581+
# here they would silently fall through to "symbol" below and neither
582+
# trigger a conversion prompt nor block the (RNA-seq-only) normalisation
583+
# steps that follow. markeR has no probe->gene mapping path (that requires
584+
# platform/GPL-specific annotation, not Ensembl/RefSeq/Entrez lookups), so
585+
# these are flagged and blocked instead of auto-converted.
586+
if (mean(grepl("^AFFX-", s, ignore.case = TRUE)) > 0.3 ||
587+
mean(grepl("^[0-9]+_(a_|s_|x_|i_)?at$", s, ignore.case = TRUE)) > 0.5 ||
588+
mean(grepl("^ILMN_[0-9]+$", s, ignore.case = TRUE)) > 0.5 ||
589+
mean(grepl("^A_[0-9]+_P[0-9]+$", s, ignore.case = TRUE)) > 0.5) {
590+
return("microarray_probe")
591+
}
579592
return("symbol")
580593
}
581594

@@ -633,6 +646,20 @@
633646
)
634647
}
635648

649+
#' Blocking card shown for every preprocessing step when microarray probe IDs
650+
#' are detected (see .pp_detect_gene_id_type / rv$microarray_blocked). Mirrors
651+
#' the visual style of the step cards but carries no controls - the full
652+
#' explanation lives in the gene ID banner above Step 0.
653+
.pp_microarray_blocked_card <- function(step_num, step_name) {
654+
bslib::card(class = "pp-step-card",
655+
bslib::card_header(shiny::tags$div(style = "display:flex;align-items:center;",
656+
shiny::tags$span(class = "pp-num", style = "background:#721c24;color:#fff;", "\U0001f6ab"),
657+
shiny::tags$strong(paste0("Step ", step_num, " - ", step_name)))),
658+
shiny::div(style = "padding:14px;color:#721c24;",
659+
"Locked: microarray probe IDs detected. See the notice above - ",
660+
"microarray data isn't supported in the Shiny app yet."))
661+
}
662+
636663
# ── HTML escaping helper (shiny::htmlEscape is not exported) ──────────────────
637664
.html_esc <- function(x) {
638665
x <- gsub("&", "&amp;", x, fixed = TRUE)
@@ -913,6 +940,8 @@ preprocessingServer <- function(id, get_expr, get_meta, log_fn = NULL, get_log =
913940
gene_id_type = "symbol",
914941
gene_id_dismissed = FALSE,
915942
gene_id_map = NULL,
943+
microarray_blocked = FALSE, # TRUE when gene_id_type == "microarray_probe" - hard-blocks
944+
# Steps 0-4 (see gene_id_banner / *_card renderUIs)
916945
data_s0_orig = NULL, # original data before any gene ID conversion
917946
downloads_available = FALSE,
918947
pp_summary = NULL,
@@ -963,6 +992,7 @@ preprocessingServer <- function(id, get_expr, get_meta, log_fn = NULL, get_log =
963992
rv$meta_s0_orig <- m # immutable snapshot for Step 0 preview (never overwritten)
964993
rv$orig_n_genes <- nrow(d0); rv$orig_n_samples <- ncol(d0)
965994
rv$gene_id_type <- .pp_detect_gene_id_type(rownames(d0))
995+
rv$microarray_blocked <- identical(rv$gene_id_type, "microarray_probe")
966996
if (is.null(prev_fp)) rv$gene_id_dismissed <- FALSE # only clear on first load
967997
})
968998

@@ -973,6 +1003,27 @@ preprocessingServer <- function(id, get_expr, get_meta, log_fn = NULL, get_log =
9731003
output$gene_id_banner <- shiny::renderUI({
9741004
shiny::req(rv$data_s0)
9751005
id_type <- rv$gene_id_type
1006+
1007+
# Microarray probe IDs are a hard block, not a dismissible prompt - the
1008+
# Shiny app doesn't support microarray data yet, so there is nothing to
1009+
# offer here (no "convert" or "skip" button). See step1_card...
1010+
# step4_card for where this also locks the rest of the preprocessing
1011+
# pipeline.
1012+
if (identical(id_type, "microarray_probe")) {
1013+
return(shiny::div(class = "pp-geneid-banner",
1014+
style = "background:#f8d7da;border:1px solid #f5c6cb;",
1015+
shiny::tags$h6(style = "margin-bottom:6px;font-weight:700;color:#721c24;",
1016+
"\U0001f6ab Microarray probe IDs detected - not yet supported"),
1017+
shiny::tags$p(style = "font-size:0.86em;margin-bottom:0;color:#721c24;",
1018+
"Your row identifiers look like microarray probe IDs (e.g. Affymetrix, ",
1019+
"Illumina or Agilent probes), not gene identifiers. Microarray data isn't ",
1020+
"supported in the markeR Shiny app yet (planned for a future version). ",
1021+
"You can still analyse microarray data with the ", shiny::tags$b("markeR R package"),
1022+
" directly: preprocess your probe-level matrix to gene symbols yourself and pass ",
1023+
"it to markeR's analysis functions in R.")
1024+
))
1025+
}
1026+
9761027
# Hide once preprocessing has been finalised (any path, including
9771028
# "Skip - use data as-is") or explicitly dismissed. Converting IDs after
9781029
# finalisation wouldn't propagate to rv$final_data/downstream tabs, so
@@ -2039,6 +2090,8 @@ preprocessingServer <- function(id, get_expr, get_meta, log_fn = NULL, get_log =
20392090

20402091
output$pp_step0_card <- shiny::renderUI({
20412092
shiny::req(!is.null(rv$meta_s))
2093+
if (isTRUE(rv$microarray_blocked))
2094+
return(.pp_microarray_blocked_card(0L, "Metadata Column Types"))
20422095
meta <- rv$meta_s
20432096
cols <- colnames(meta)[-1]
20442097
if (length(cols) == 0L) return(NULL)
@@ -2433,6 +2486,8 @@ preprocessingServer <- function(id, get_expr, get_meta, log_fn = NULL, get_log =
24332486

24342487
output$step1_card <- shiny::renderUI({
24352488
e <- rv$data_s0
2489+
if (isTRUE(rv$microarray_blocked))
2490+
return(.pp_microarray_blocked_card(1L, "Sample Complexity QC"))
24362491
if (is.null(e))
24372492
return(bslib::card(class="pp-step-card",
24382493
bslib::card_header(shiny::tags$div(style="display:flex;align-items:center;",
@@ -2670,6 +2725,8 @@ preprocessingServer <- function(id, get_expr, get_meta, log_fn = NULL, get_log =
26702725
}, ignoreInit=TRUE)
26712726

26722727
output$step2_card <- shiny::renderUI({
2728+
if (isTRUE(rv$microarray_blocked))
2729+
return(.pp_microarray_blocked_card(2L, "Filter Lowly Expressed Genes"))
26732730
if (rv$step < 2L)
26742731
return(shiny::div(class="pp-locked",
26752732
bslib::card(class="pp-step-card",
@@ -2790,6 +2847,8 @@ preprocessingServer <- function(id, get_expr, get_meta, log_fn = NULL, get_log =
27902847
# =========================================================================
27912848

27922849
output$step3_card <- shiny::renderUI({
2850+
if (isTRUE(rv$microarray_blocked))
2851+
return(.pp_microarray_blocked_card(3L, "Normalisation"))
27932852
if (rv$step < 3L)
27942853
return(shiny::div(class="pp-locked",
27952854
bslib::card(class="pp-step-card",
@@ -3051,6 +3110,8 @@ preprocessingServer <- function(id, get_expr, get_meta, log_fn = NULL, get_log =
30513110
# =========================================================================
30523111

30533112
output$step4_card <- shiny::renderUI({
3113+
if (isTRUE(rv$microarray_blocked))
3114+
return(.pp_microarray_blocked_card(4L, "PCA & Batch Correction"))
30543115
if (rv$step < 4L)
30553116
return(shiny::div(class="pp-locked",
30563117
bslib::card(class="pp-step-card",

‎R/markeR_tab_data.R‎

Lines changed: 98 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -396,47 +396,46 @@ dataServer <- function(input, output, session) {
396396
full_geo_meta <- reactiveVal(NULL)
397397
upload_meta_raw <- reactiveVal(NULL) # Raw uploaded metadata (for SampleID re-mapping)
398398
module_meta_active <- reactiveVal(FALSE) # TRUE while geo_import_module owns meta_data()
399-
# Session log: initialise with R + all DESCRIPTION dependency versions.
400-
.session_preamble <- tryCatch({
401-
# Parse Imports + Suggests + Depends from the installed package DESCRIPTION
402-
.parse_dep_field <- function(field) {
403-
if (is.null(field) || is.na(field)) return(character(0))
404-
pkgs <- strsplit(field, ",")[[1]]
405-
pkgs <- trimws(sub("\\s*\\(.*?\\)", "", pkgs)) # strip version specs like (>= 4.0)
406-
pkgs[nzchar(pkgs) & pkgs != "R"]
407-
}
408-
desc <- utils::packageDescription("markeR",
409-
fields = c("Imports", "Suggests", "Depends"))
410-
pkgs <- sort(unique(c(
411-
"markeR",
412-
.parse_dep_field(desc$Imports),
413-
.parse_dep_field(desc$Suggests),
414-
.parse_dep_field(desc$Depends)
415-
)))
416-
pkg_lines <- vapply(pkgs, function(p) {
417-
v <- tryCatch(as.character(utils::packageVersion(p)), error = function(e) "not installed")
418-
paste0("[Session] ", p, ": ", v) # note: ALL lines prefixed with [Session]
419-
}, character(1L))
420-
c(
421-
paste0("[Session] Session started: ", format(Sys.time(), "%Y-%m-%d %H:%M:%S")),
422-
paste0("[Session] R version: ", R.version$major, ".", R.version$minor,
423-
" (", R.version$`svn rev`, ") | Platform: ", R.version$platform),
424-
"[Session] Package versions:",
425-
pkg_lines
426-
)
427-
}, error = function(e) character(0))
399+
# Session log: initialise with the same R-version/package-version
400+
# preamble baked into the static UI's global_log_entries placeholder
401+
# (see .markeR_session_preamble() in R/markeRapp.R for the full
402+
# rationale). Calling it again here (rather than reusing
403+
# .markeR_initial_session_lines directly) just gives this session's own
404+
# "Session started" timestamp; the package/version lines are identical
405+
# either way.
406+
.session_preamble <- .markeR_session_preamble()
428407
data_log <- reactiveVal(.session_preamble) # Session log with timestamped entries
429408
expr_quality_warn <- reactiveVal(NULL) # Warning message for suspicious expression data
430409
geo_supp_files <- reactiveVal(NULL)
431410
expr_candidates_available <- reactiveVal(FALSE) # Flag to indicate multiple candidate files are available after auto detection
432-
411+
412+
# For reasons not fully pinned down (tried and ruled out: an initial-
413+
# visibility suspension - already disabled via suspendWhenHidden = FALSE
414+
# below - and a fixed-delay/polling "kick", which caused visible
415+
# flicker), the very FIRST successful invalidation + recompute of
416+
# global_log_header/global_log_entries in a session does not reliably
417+
# reach the client - only a second one, from a genuinely separate flush,
418+
# does. Rather than guess at timing, every place that changes data_log()
419+
# also schedules exactly one follow-up nudge via session$onFlushed(once
420+
# = TRUE), which fires right after Shiny finishes the "real" flush - so
421+
# essentially immediately, not on any arbitrary clock - making it
422+
# imperceptible rather than a visible re-render.
423+
.log_kick <- shiny::reactiveVal(0L)
424+
.nudge_log <- function() {
425+
session$onFlushed(function() {
426+
.log_kick(shiny::isolate(.log_kick()) + 1L)
427+
}, once = TRUE)
428+
}
429+
.nudge_log() # covers the very first render too (before any log_step() call)
430+
433431
# Append a timestamped entry to the processing log.
434432
# isolate() prevents the calling observer from taking a reactive dependency
435433
# on data_log - without it, writing data_log() re-invalidates the observer
436434
# that called log_step(), causing an infinite reactive loop.
437435
log_step <- function(msg) {
438436
ts <- format(Sys.time(), "[%Y-%m-%d %H:%M:%S]")
439437
data_log(c(isolate(data_log()), paste(ts, msg)))
438+
.nudge_log()
440439
}
441440

442441
###### HELPER FUNCTIONS ######
@@ -1045,6 +1044,24 @@ dataServer <- function(input, output, session) {
10451044
}
10461045
})
10471046

1047+
# ── Revert to example data when a GEO import fails outright ──────────────
1048+
# "excluded"/"error" mean no usable expr/meta came back (unsupported assay
1049+
# type - e.g. microarray, scRNA, ChIP-seq - or a download/parse failure).
1050+
# Left alone, the "Retrieve from GEO" radio would stay selected while
1051+
# expr_data()/meta_data() still held whatever was loaded before the failed
1052+
# attempt, making it unclear whether the Data tab is showing the (failed)
1053+
# GEO import or leftover previous data. Switching back to the example data
1054+
# radio re-triggers the existing input$expr_source observer above, which
1055+
# loads fresh example data and resets meta_source to match - so the app
1056+
# state unambiguously reflects "GEO import did not take effect."
1057+
observeEvent(geo_module$status(), {
1058+
req(input$expr_source == "geo")
1059+
if (geo_module$status() %in% c("excluded", "error")) {
1060+
log_step("GEO import failed - reverting to example data.")
1061+
updateRadioButtons(session, "expr_source", selected = "example_raw")
1062+
}
1063+
}, ignoreInit = TRUE)
1064+
10481065
# ── Legacy helpers kept for the non-GEO upload path ─────────────────────
10491066

10501067
##### METADATA #########################################
@@ -1654,7 +1671,21 @@ dataServer <- function(input, output, session) {
16541671
})
16551672

16561673
# ── Global log bar (fixed bottom - visible across all tabs) ───────────────
1674+
# NOTE: suspendWhenHidden = FALSE is essential for both outputs below.
1675+
# #global-log-header uses display:flex, so an empty child <div>/<span>
1676+
# sizes to its own (empty) content rather than the container's width -
1677+
# i.e. genuinely zero-size before its first render. Shiny automatically
1678+
# suspends (never even evaluates) a render function it judges bound to a
1679+
# "not visible" element, using exactly this kind of zero-size check. That
1680+
# is a real deadlock: the element only gains size once it has content,
1681+
# and it only gets content once Shiny decides to run it. Likewise
1682+
# #global-log-entries starts inside #global-log-body, which is
1683+
# collapsed to max-height:0 until the bar is clicked open - also read as
1684+
# "hidden" at the moment Shiny would otherwise compute the very first
1685+
# value. Without disabling suspension here, neither output ever runs
1686+
# until something incidentally gives its container real size later on.
16571687
output$global_log_header <- shiny::renderUI({
1688+
.log_kick() # see .nudge_log() above
16581689
log <- data_log()
16591690
n <- sum(!startsWith(log, "[Session]")) # count only action entries
16601691
shiny::tags$span(
@@ -1665,8 +1696,10 @@ dataServer <- function(input, output, session) {
16651696
" - click to expand)")
16661697
)
16671698
})
1699+
shiny::outputOptions(output, "global_log_header", suspendWhenHidden = FALSE)
16681700

16691701
output$global_log_entries <- shiny::renderUI({
1702+
.log_kick() # see .nudge_log() above
16701703
log <- data_log()
16711704
action_lines <- log[!startsWith(log, "[Session]")]
16721705
session_lines <- log[startsWith(log, "[Session]")]
@@ -1701,6 +1734,7 @@ dataServer <- function(input, output, session) {
17011734
)
17021735
)
17031736
})
1737+
shiny::outputOptions(output, "global_log_entries", suspendWhenHidden = FALSE)
17041738

17051739
output$download_log <- shiny::downloadHandler(
17061740
filename = function() paste0("markeR_session_log_",
@@ -1996,21 +2030,39 @@ dataServer <- function(input, output, session) {
19962030
)
19972031
})
19982032

2033+
# NOTE: expr_preview can easily be tens of thousands of genes x hundreds
2034+
# of samples (e.g. 13804 x 545 - ~7.5M cells). Returning a fully-built
2035+
# DT::datatable() object from inside renderDT(), as this used to do,
2036+
# forces DT into CLIENT-SIDE processing regardless of any `server`
2037+
# setting - DT only honours server-side processing when the render
2038+
# function's expression returns a plain data object and `server = TRUE`
2039+
# is passed to renderDT() itself. Client-side processing serializes the
2040+
# *entire* matrix to JSON and ships it to the browser in one go, which is
2041+
# both extremely slow for a table this size and a plausible trigger for
2042+
# DataTables' internal state getting corrupted under load (matching a
2043+
# client-side "Cannot read properties of null (reading 'lazyRender')"
2044+
# error seen from DT's own htmlwidgets binding code). Passing plain data
2045+
# here and moving pageLength/scrollX/etc. to renderDT()'s own arguments
2046+
# keeps server-side processing on, so only the current page of data is
2047+
# ever sent to the browser.
19992048
output$expr_preview <- DT::renderDT({
20002049
shiny::req(expr_data())
2001-
2002-
DT::datatable(
2003-
round(expr_data(),2), # round for better display
2004-
options = list(
2005-
pageLength = 5,
2006-
lengthMenu = c(5, 10, 20, 50),
2007-
scrollX = TRUE,
2008-
scrollY = "250px", # <-- added vertical scroll
2009-
paging = TRUE
2010-
),
2011-
rownames = TRUE
2012-
)
2013-
})
2050+
round(expr_data(), 2) # round for better display
2051+
},
2052+
server = TRUE,
2053+
options = list(
2054+
pageLength = 5,
2055+
lengthMenu = c(5, 10, 20, 50),
2056+
scrollX = TRUE,
2057+
scrollY = "250px", # <-- added vertical scroll
2058+
deferRender = TRUE, # DataTables' own recommended pairing with
2059+
# scrollY - initialising a scrolling body
2060+
# without it is a known trigger for internal
2061+
# DataTables/DT client-side errors
2062+
paging = TRUE
2063+
),
2064+
rownames = TRUE
2065+
)
20142066

20152067
output$meta_preview <- DT::renderDT({
20162068
shiny::req(meta_data())
@@ -2022,6 +2074,7 @@ dataServer <- function(input, output, session) {
20222074
lengthMenu = c(5, 10, 20, 50),
20232075
scrollX = TRUE,
20242076
scrollY = "250px", # <-- added vertical scroll
2077+
deferRender = TRUE, # see note on expr_preview above
20252078
paging = TRUE
20262079
),
20272080
rownames = FALSE
@@ -2062,6 +2115,7 @@ dataServer <- function(input, output, session) {
20622115
pageLength = 5,
20632116
scrollX = TRUE,
20642117
scrollY = "250px",
2118+
deferRender = TRUE, # see note on expr_preview above
20652119
lengthMenu = c(5, 10, 20, 50),
20662120
escape = FALSE # allows + and parentheses to display properly
20672121

@@ -2102,6 +2156,7 @@ dataServer <- function(input, output, session) {
21022156
pageLength = 10,
21032157
scrollX = TRUE,
21042158
scrollY = "300px", # height of scrollable area
2159+
deferRender = TRUE, # see note on expr_preview above
21052160
scrollCollapse = TRUE, # collapse if fewer rows
21062161
paging = FALSE, # optional, better for modal scroll
21072162
columnDefs = list(

‎R/markeR_tab_gene_sets.R‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,10 @@ geneSetsServer <- function(id, get_expr, get_meta, get_gene_sets) {
11331133
sprintf("Composition (%d gene%s)", nrow(df), if (nrow(df) != 1) "s" else ""))),
11341134
DT::datatable(df, rownames = FALSE, filter = "none",
11351135
options = list(paging = FALSE, dom = "ft", scrollY = "260px",
1136+
deferRender = TRUE, # see note on expr_preview in
1137+
# markeR_tab_data.R - DataTables'
1138+
# own recommended pairing with
1139+
# scrollY
11361140
scrollCollapse = TRUE, scrollX = FALSE,
11371141
columnDefs = list(list(className = "dt-left", targets = "_all"))))
11381142
)

0 commit comments

Comments
 (0)