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

Use output_code() and render.code() #1421

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/dataframe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def app_ui(req):
ui.input_switch("fullwidth", "Take full width", True),
ui.output_data_frame("grid"),
ui.panel_fixed(
ui.output_text_verbatim("detail"),
ui.output_code("detail"),
right="10px",
bottom="10px",
),
Expand Down Expand Up @@ -97,7 +97,7 @@ def handle_edit():
df_copy.iat[edit["row"], edit["col"]] = edit["new_value"]
df.set(df_copy)

@render.text
@render.code
def detail():
selected_rows = (grid.cell_selection() or {}).get("rows", ())
if len(selected_rows) > 0:
Expand Down
2 changes: 1 addition & 1 deletion examples/express/accordion_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

with ui.accordion_panel("Panel 2"):

@render.text
@render.code
def txt():
return f"n = {input.n()}"

Expand Down
2 changes: 1 addition & 1 deletion examples/express/basic_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
ui.input_slider("n", "N", 1, 100, 50)


@render.text()
@render.code()
def txt():
return f"n = {input.n()}"
4 changes: 2 additions & 2 deletions examples/express/hold_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# `ui.hold()` can be used to just suppress output
with ui.hold():

@render.text()
@render.code()
def txt():
return f"Slider value: {input.n()}"


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

shiny.ui.output_text("txt", inline=True)
shiny.ui.output_code("txt", inline=True)
4 changes: 2 additions & 2 deletions examples/express/shared_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def _():
shared.rv.set(input.n())


@render.text
@render.code
def rv_value():
return f"shared.rv() = {shared.rv()}"


@render.text
@render.code
def text_data():
return "shared.data = " + str(shared.data)

Expand Down
8 changes: 4 additions & 4 deletions examples/headers/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

app_ui = ui.page_fluid(
ui.h3("HTTP request headers"),
ui.output_text_verbatim("headers", placeholder=True),
ui.output_code("headers", placeholder=True),
ui.h3("User and groups"),
ui.output_text_verbatim("user_groups", placeholder=True),
ui.output_code("user_groups", placeholder=True),
)


def server(input: Inputs, output: Outputs, session: Session):
@render.text
@render.code
def headers():
s = ""
for key, value in session.http_conn.headers.items():
s += f"{key}: {value}\n"

return s

@render.text
@render.code
def user_groups():
return f"session.user: {session.user}\nsession.groups: {session.groups}"

Expand Down
4 changes: 2 additions & 2 deletions examples/moduleapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def counter_ui(label: str = "Increment counter") -> ui.TagChild:
return ui.card(
ui.h2("This is " + label),
ui.input_action_button(id="button", label=label),
ui.output_text_verbatim(id="out"),
ui.output_code(id="out"),
)


Expand All @@ -24,7 +24,7 @@ def counter_server(
def _():
count.set(count() + 1)

@render.text
@render.code
def out() -> str:
return f"Click count is {count()}"

Expand Down
14 changes: 7 additions & 7 deletions examples/typed_inputs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
ui.input_numeric("n", "N", 20),
ui.input_numeric("n2", "N2", 50),
ui.input_checkbox("checkbox", "Checkbox", True),
ui.output_text_verbatim("txt", placeholder=True),
ui.output_text_verbatim("txt2", placeholder=True),
ui.output_text_verbatim("txt3", placeholder=True),
ui.output_code("txt", placeholder=True),
ui.output_code("txt2", placeholder=True),
ui.output_code("txt3", placeholder=True),
)


Expand Down Expand Up @@ -42,19 +42,19 @@ def r():
# thinks the return type of input.n() is Any, so we don't get type checking here.
# The function is returning the wrong value here: it returns an int instead of a
# string, but this error is not flagged.
@render.text
@render.code
async def txt():
return input.n() * 2

# In contrast, input.n2() is declared to return an int, so the type check does flag
# this error -- the `render.text()` is underlined in red.
@render.text
# this error -- the `render.code()` is underlined in red.
@render.code
async def txt2():
return input.n2() * 2

# This is a corrected version of the function above. It returns a string, and is not
# marked in red.
@render.text
@render.code
async def txt3():
return str(input.n2() * 2)

Expand Down
Loading