cjerzak commited on
Commit
177c265
·
verified ·
1 Parent(s): b360764

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +21 -34
app.R CHANGED
@@ -311,40 +311,27 @@ server <- function(input, output, session) {
311
  })
312
 
313
  # Auto-compute results on startup with defaults
314
- observe({
315
- # Only run once when the app starts and inputs are available
316
- if (!is.null(input$case_type) && !is.null(input$lambda_input)) {
317
- # Trigger computation with default values
318
- withProgress(message = "Loading default results...", value = 0, {
319
- incProgress(0.2, detail = "Looking up precomputed results...")
320
-
321
- # Use default values: Average case, All respondents, lambda 0.01
322
- case_type <- "Average"
323
- respondent_group <- "All"
324
- lambda_input <- 0.01
325
-
326
- label <- paste("Case=Average, Group=All, Lambda=0.01", sep="")
327
- lam_char <- gsub("\\.", "PT", as.character(lambda_input))
328
- filename <- paste0("Average_All_lambda", lam_char, ".rds")
329
-
330
- # Read the matching pre-computed .rds file from disk
331
- file_path <- file.path("AppResults", filename)
332
- if (file.exists(file_path)) {
333
- Qoptimized <- readRDS(file_path)
334
-
335
- # Store the loaded results in our reactive cache
336
- cachedResults$data[[label]] <- Qoptimized
337
-
338
- incProgress(0.8, detail = "Finishing up...")
339
-
340
- # Update the choice list for previous results
341
- updateSelectInput(session, "previousResults",
342
- choices = names(cachedResults$data),
343
- selected = label)
344
- }
345
- })
346
- }
347
- },once=TRUE)
348
 
349
  # Generate a new result and cache it
350
  # -- In app_ono.R, inside `server` definition --
 
311
  })
312
 
313
  # Auto-compute results on startup with defaults
314
+ session$onFlushed(function() {
315
+ withProgress(message = "Loading default results...", value = 0, {
316
+ incProgress(0.2, detail = "Looking up precomputed results...")
317
+
318
+ # Use default values: Average case, All respondents, lambda 0.01
319
+ lambda_input <- 0.01
320
+ label <- "Case=Average, Group=All, Lambda=0.01"
321
+ lam_char <- gsub("\\.", "PT", as.character(lambda_input))
322
+ filename <- paste0("Average_All_lambda", lam_char, ".rds")
323
+
324
+ file_path <- file.path("AppResults", filename)
325
+ if (file.exists(file_path)) {
326
+ Qoptimized <- readRDS(file_path)
327
+ cachedResults$data[[label]] <- Qoptimized
328
+ incProgress(0.8, detail = "Finishing up...")
329
+ updateSelectInput(session, "previousResults",
330
+ choices = names(cachedResults$data),
331
+ selected = label)
332
+ }
333
+ })
334
+ }, once = TRUE)
 
 
 
 
 
 
 
 
 
 
 
 
 
335
 
336
  # Generate a new result and cache it
337
  # -- In app_ono.R, inside `server` definition --