Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(express): Automatically suppress non-renderable UI objects #1773

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gadenbuie
Copy link
Collaborator

@gadenbuie gadenbuie commented Nov 14, 2024

For #1771

Example app:

import duckdb
import pandas as pd

from shiny.express import input, render, ui

# Create a sample DataFrame
df = pd.DataFrame(
    {
        "id": range(1, 6),
        "name": ["Alice", "Bob", "Charlie", "David", "Eve"],
        "age": [25, 30, 35, 28, 22],
    }
)


# Register DataFrame with DuckDB
con = duckdb.connect(":memory:")
con.register("people", df)

ui.input_select("person", "Choose a person:", choices=df["name"].tolist())


@render.text()
def value():
    res = con.execute("SELECT age FROM people WHERE name = ?", [input.person()])
    return f"You choose: {input.person()} who is {res.fetchone()[0]} years old."

As mentioned in #1771 the above example app would fail to launch in Shiny Express due to the con.register() line. This PR makes is so that lines with un-renderable objects are not introduced in the UI.

It gives a warning message like the following, which we could wordsmith as needed. (Currently a print() call but we might be able to use warnings.warn() to include more context.)

Express has suppressed the object `<duckdb.duckdb.DuckDBPyConnection object at 0x126107a70>`
because it is of type <class 'duckdb.duckdb.DuckDBPyConnection'>. Coerce to HTML, a string,
or an htmltools tag to display this object.

@gadenbuie gadenbuie force-pushed the express/only-show-renderable-objects branch from 6e90032 to 145b5cc Compare November 14, 2024 21:06
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.

1 participant