[BUG] is_running() returns FALSE while the app is running

Open
#1,260 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
backend

Research direction

Start in R/with_opt.R, where with_golem_options() sets the running flag and resets it with on.exit(), then look at is_running() and get_golem_options() to see how they read state. Run the reproduction in the issue and watch the console for is_running() at UI time. Test/test-is_running.R sets the global by hand, so the fix needs a test that serves the app. Done when is_running() returns TRUE inside a served app and that test passes.

Written by the indexing model from the issue text.

Description

bug

Describe the bug

is_running() returns FALSE while a {golem} app is actually being served.

with_golem_options() sets the running flag, then resets it with on.exit() (R/with_opt.R#L40-L51). But with_golem_options() returns the shiny.appObj before shiny runs it (the app is started later by print() / runApp()), so the flag is always FALSE by the time the UI and server functions execute. The only exception is print = TRUE.

The current test (test-is_running.R) sets .golem_globals$running by hand, so it doesn't catch this.

To Reproduce

library(golem)
app <- with_golem_options(
  app = shiny::shinyApp(
    ui = function(request) {
      message(
        "is_running(): ", is_running(),
        " | get_golem_options('title'): ", get_golem_options("title")
      )
      shiny::div()
    },
    server = function(input, output, session) {}
  ),
  golem_opts = list(
    title = "x"
  )
)
shiny::runApp(
  app,
  port = 8765,
  launch.browser = FALSE
)

Then open http://127.0.0.1:8765. The console shows:

is_running(): FALSE | get_golem_options('title'): x

Expected behavior

is_running() returns TRUE inside an app launched through with_golem_options().

Additional context

get_golem_options() works at runtime because the options are stored in app$appOptions. A possible fix is to derive the status from there, e.g. !is.null(shiny::getShinyOption("golem_options")), instead of a global flag. That would need a test that actually serves the app.

session info

R 4.3.3, Ubuntu 24.04, {golem} master (9938a41, version 1.0.1).


Generated by Claude Code

Dominant language
R
Stars
947
Forks
135
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ThinkR-open/golem

All issues in ThinkR-open/golem

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.