@@ -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 (
0 commit comments