Skip to content

Conversation

wch
Copy link
Collaborator

@wch wch commented Jan 19, 2024

This PR supersedes #996. It does the following:

  • Rename express.suspend_display -> express.ui.hold
  • Rename express.display_body -> express.expressify
  • Rename render.display -> render.express

Also, for hold:

  • hold() now can only be used a context manager, and not as a decorator.
  • You can do with ui.hold() as x, and then use x later on the page to display it.

Note that suspend_display is basically an alias for hold, and in this PR it has lost the ability to be used as a decorator, which could break code that was using the previous (experimental) API.

Example usage for hold:

import shiny.ui
from shiny.express import input, render, ui

# `ui.hold() as x` can be used to save `x` for later output
with ui.hold() as hello_card:
    with ui.card():
        with ui.span():
            "This is a"
            ui.span(" card", style="color: red;")

hello_card
hello_card


# ================================================

# `ui.hold()` can be used to just suppress output
with ui.hold():
    @render.text()
    def txt():
        return f"Slider value: {input.n()}"


ui.input_slider("n", "N", 1, 100, 50)
shiny.ui.output_text("txt", inline=True)

Example for expressify:

from shiny.express import expressify, ui

# @expressify converts a function to work with Express syntax
@expressify
def expressified1(s: str):
    f"Expressified function 1: {s}"
    ui.br()


expressified1("Hello")
expressified1("world")

Example for render.express:

from shiny.express import input, render, ui

ui.input_slider("n", "N", 1, 100, 50)

# @render.express is like @render.ui, but with Express syntax
@render.express
def render_express1():
    "Slider value:"
    input.n()

This was referenced Jan 19, 2024
@wch wch requested a review from jcheng5 January 19, 2024 22:10


class display(Renderer[None]):
class express(Renderer[None]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No docstrings for this yet? (Or do they live somewhere else?)

@wch wch merged commit 8127f1a into main Jan 19, 2024
@wch wch deleted the hold branch January 19, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants