Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`builtin_handler_shiny` results in Error: attempt to apply non-function

Open
#762 2 comments 0 reactions 0 assignees View on GitHub

@taekop is already working on this.

Since Oct 5, 2026.

  • #846 by @taekop — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
cli

Research direction

Start with R/progress-server.R around lines 356-365 and inspect the lifecycle of builtin_handler_shiny, especially complete(), set(), and output(). Reproduce the post-completion call sequence described in targets issue 1478; done means the shiny handler no longer raises a non-function error when progress operations occur after completion.

Written by the indexing model from the issue text.

Description

bug

Dear cli maintainer, I recently encountered an issue https://github.com/ropensci/targets/issues/1478 (please check this issue for more detailed examples)

The targets package probably tried using cli progress bar before initialized ("add") or after completion, resulting in an error. The related code is here

https://github.com/r-lib/cli/blob/main/R/progress-server.R#L356C1-L365C5

We see that shiny progress is set to NULL, and then trying to access functions such as output or set will raise errors.

bar$shiny_progress <- NULL

Basically if shiny ends the progress bar builtin_handler_shiny$complete() and the program still tries to call builtin_handler_shiny $output(), then the code will error out in shiny app. However, the code works fine outside of shiny, which makes the debugging process extremely hard.

I understand that if the package is used super carefully, then this issue will not occur. However, it is often the case that the package does not mandate what people do, especially when the code just works for most of people. Considering that other handlers do not raise errors on "use-after-free", and condition that triggers this error, this inconsistency is super hard to debug/find.

However, could we add checks just to make sure the functions are not that stringent? Alternatively, if you would like to ensure consistent behavior, we can force set and output to result in errors after completion for other functions.

builtin_handler_shiny <- list(
  able = function(bar, .envir) {
    "shiny" %in% loadedNamespaces() && asNamespace("shiny")$isRunning()
  },

  add = function(bar, .envir) {
    bar$shiny_progress <- asNamespace("shiny")$Progress$new(
      asNamespace("shiny")$getDefaultReactiveDomain(),
      min = 0,
      max = bar$total
    )
    bar$shiny_progress$set(
      message = bar$name %||% "",
      detail = shiny_detail(bar, .envir)
    )
  },

  set = function(bar, .envir) {
    if(!is.null(bar$shiny_progress)) {
      bar$shiny_progress$set(
        value = bar$current,
        detail = shiny_detail(bar, .envir)
      )
    }
  },

  complete = function(bar, .envir, results) {
    if (!is.null(bar$shiny_progress)) {
      bar$shiny_progress$set(
        value = bar$current,
        detail = shiny_detail(bar, .envir)
      )
      bar$shiny_progress$close()
    }
    bar$shiny_progress <- NULL
  },

  output = function(bar, .envir, text) {
    bar$shiny_output <-
      last_lines(paste0(bar$shiny_output, " \u2022 ", text))
    if(!is.null(bar$shiny_progress)) {
      bar$shiny_progress$set(
        value = bar$current,
        detail = shiny_detail(bar, .envir)
      )
    }
  }
)
Dominant language
R
Stars
730
Forks
95
Avg merge
1d 18h
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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 r-lib/cli

All issues in r-lib/cli

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.