Can we remove values from shinyoutput object?

Can we remove elements from a shinyoutput object?
Basic testing suggests no:

## in shinyServer(function(input, output, session)):

output$foo <- renderText("foo")

## rm(output[["foo"]]) ## doesn't work
## output[["foo"]] <- NULL ## also doesn't work

The reason for wanting such a function is to prevent server-side memory leaks in long-running applications that frequently call insertUI() and removeUI().

For example, insertUI() might insert a dynamically-generated textOutput("foo", ...) element with a corresponding output[["foo"]] <- renderText(...) assignment to the session's output object. Now, when removeUI() removes the textOutput("foo", ...) element, I'd like to 'clean-up' the session's output object by removing the "foo" entry.

For applications where this is a frequent procedure and where the ID ("foo") is dynamically-generated, the UI can be kept tidy, but I suspect the server-side output object simply continues to accumulate these entries.

Is there any way to remove a specific entry in the output object by that entry's ID?

1 Like