Skip to content

Need stronger ui.hold()-like context manager for non-UI objects #1083

Open
@jcheng5

Description

@jcheng5

We need another context manager, maybe ui.discard(), to prevent Shiny Express from trying to interpret non-UI objects as UI. Or, perhaps Shiny Express should not be so strict about what kinds of objects are allowed to be displayhooked (no-op instead of error).

from shiny.express import ui

class A:
    def __init__(self):
        self.options = {}

    def set_option(self, name, value):
        self.options[name] = value
        
        # for method chaining purposes
        return self

a = A()

# This next line causes the error.
# Enclosing the line in `with ui.hold()` does not help.
a.set_option("host", "localhost")

with ui.card():
    "Hello"

For now the best workaround I can think of is to turn such lines into dummy assignment statements, like _ = a.set_option("host", "localhost"), but that is not very satisfying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions