Skip to content

Remove @output from examples #790

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

Merged
merged 5 commits into from
Dec 19, 2023
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### New features
* `shiny run` now takes `reload-includes` and `reload-excludes` to allow you to define which files trigger a reload (#780).
* `shiny.run` now passes keyword arguments to `uvicorn.run` (#780).
* The `@output` decorator is no longer required for rendering functions; `@render.xxx` decorators now register themselves automatically. You can still use `@output` explicitly if you need to set specific output options (#747).
* The `@output` decorator is no longer required for rendering functions; `@render.xxx` decorators now register themselves automatically. You can still use `@output` explicitly if you need to set specific output options (#747, #790).
* Added support for integration with Quarto (#746).
* Added `shiny.render.renderer_components` decorator to help create new output renderers (#621).
* Added `shiny.experimental.ui.popover()`, `update_popover()`, and `toggle_popover()` for easy creation (and server-side updating) of [Bootstrap popovers](https://getbootstrap.com/docs/5.3/components/popovers/). Popovers are similar to tooltips, but are more persistent, and should primarily be used with button-like UI elements (e.g. `input_action_button()` or icons) (#680).
Expand Down
3 changes: 0 additions & 3 deletions examples/airmass/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def df() -> Dict[str, pd.DataFrame]:
for (altaz, obj) in zip(altaz_list, obj_names())
}

@output
@render.plot
def plot():
fig, [ax1, ax2] = plt.subplots(nrows=2)
Expand Down Expand Up @@ -160,12 +159,10 @@ def add_boundary(ax, xval):

return fig

@output
@render.table
def table() -> pd.DataFrame:
return pd.concat(df())

@output
@render.ui
def timeinfo():
start_utc, end_utc = times_utc()
Expand Down
3 changes: 0 additions & 3 deletions examples/annotation-export/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def _():
df = df.loc[:, ["date", "temp_c", "annotation"]]
annotated_data.set(df)

@output
@render.plot
def time_series():
fig, ax = plt.subplots()
Expand All @@ -76,7 +75,6 @@ def time_series():
out.tick_params(axis="x", rotation=30)
return out.get_figure()

@output
@render.ui
def annotator():
if input.time_series_brush() is not None:
Expand Down Expand Up @@ -104,7 +102,6 @@ def annotator():
)
return out

@output
@render.data_frame
def annotations():
df = annotated_data().copy()
Expand Down
4 changes: 0 additions & 4 deletions examples/brownian/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,18 @@ def update_plotly_camera():

# DEBUGGING ====

@output
@render.text
def x_debug():
return camera_eye()["x"]

@output
@render.text
def y_debug():
return camera_eye()["y"]

@output
@render.text
def z_debug():
return camera_eye()["z"]

@output
@render.text
def mag_debug():
eye = camera_eye()
Expand Down
2 changes: 0 additions & 2 deletions examples/cpuinfo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def collect_cpu_samples():
def reset_history():
cpu_history.set(None)

@output
@render.plot
def plot():
history = cpu_history_with_hold()
Expand Down Expand Up @@ -205,7 +204,6 @@ def plot():

return fig

@output
@render.table
def table():
history = cpu_history_with_hold()
Expand Down
2 changes: 0 additions & 2 deletions examples/dataframe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def server(input: Inputs, output: Outputs, session: Session):
def update_df():
return df.set(sns.load_dataset(req(input.dataset())))

@output
@render.data_frame
def grid():
height = 350
Expand Down Expand Up @@ -91,7 +90,6 @@ def handle_edit():
df_copy.iat[edit["row"], edit["col"]] = edit["new_value"]
df.set(df_copy)

@output
@render.text
def detail():
if (
Expand Down
1 change: 0 additions & 1 deletion examples/duckdb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def query_output_ui(remove_id, qry="SELECT * from weather LIMIT 10"):
def query_output_server(
input, output, session, con: duckdb.DuckDBPyConnection, remove_id
):
@output
@render.data_frame
def results():
# In order to avoid the query re-running with each keystroke we
Expand Down
1 change: 0 additions & 1 deletion examples/event/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ async def _():
val = await btn_async_r()
print("async @calc() event: ", str(val))

@output
@render.ui
@reactive.event(btn_async_r)
async def btn_async_value():
Expand Down
2 changes: 0 additions & 2 deletions examples/global_pyplot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@


def server(input: Inputs, output: Outputs, session: Session):
@output
@render.plot
def mpl():
if input.render():
plt.hist([1, 1, 2, 3, 5])

@output
@render.plot
async def mpl_bad():
if input.render():
Expand Down
2 changes: 0 additions & 2 deletions examples/headers/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


def server(input: Inputs, output: Outputs, session: Session):
@output
@render.text
def headers():
s = ""
Expand All @@ -18,7 +17,6 @@ def headers():

return s

@output
@render.text
def user_groups():
return f"session.user: {session.user}\nsession.groups: {session.groups}"
Expand Down
1 change: 0 additions & 1 deletion examples/load_balance/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@


def server(input: Inputs, output: Outputs, session: Session):
@output
@render.ui
def out():
# Register a dynamic route for the client to try to connect to.
Expand Down
3 changes: 0 additions & 3 deletions examples/model-score/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def filtered_df():
def filtered_model_names():
return filtered_df()["model"].unique()

@output
@render.ui
def value_boxes():
data = filtered_df()
Expand Down Expand Up @@ -208,7 +207,6 @@ def value_boxes():
fixed_width=True,
)

@output
@render_plotly_streaming(recreate_key=filtered_model_names, update="data")
def plot_timeseries():
"""
Expand Down Expand Up @@ -249,7 +247,6 @@ def plot_timeseries():

return fig

@output
@render_plotly_streaming(recreate_key=filtered_model_names, update="data")
def plot_dist():
fig = px.histogram(
Expand Down
3 changes: 0 additions & 3 deletions examples/moduleapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def counter_server(
def _():
count.set(count() + 1)

@output
@render.text
def out() -> str:
return f"Click count is {count()}"
Expand All @@ -44,7 +43,6 @@ def counter_wrapper_ui() -> ui.TagChild:
def counter_wrapper_server(
input: Inputs, output: Outputs, session: Session, label: str = "Increment counter"
):
@output()
@render.ui()
def dynamic_counter():
return counter_ui("counter", label)
Expand All @@ -66,7 +64,6 @@ def server(input: Inputs, output: Outputs, session: Session):
counter_server("counter1")
counter_wrapper_server("counter2_wrapper", "Counter 2")

@output()
@render.ui()
def counter3_ui():
counter_server("counter3")
Expand Down
4 changes: 1 addition & 3 deletions examples/penguins/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def filtered_df() -> pd.DataFrame:
# Filter the rows so we only include the desired species
return df[df["Species"].isin(input.species())]

@output
@render.plot
def scatter():
"""Generates a plot for Shiny to display to the user"""
Expand All @@ -81,7 +80,6 @@ def scatter():
legend=False,
)

@output
@render.ui
def value_boxes():
df = filtered_df()
Expand Down Expand Up @@ -124,7 +122,7 @@ def penguin_value_box(title: str, count: int, bgcol: str, showcase_img: str):
if name in input.species()
]

return ui.layout_column_wrap(1 / len(value_boxes), *value_boxes)
return ui.layout_column_wrap(*value_boxes, width=1 / len(value_boxes))


app = App(
Expand Down
3 changes: 0 additions & 3 deletions examples/req/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def safe_click():
req(input.safe())
return input.safe()

@output
@render.ui
def safe():
raise SafeException(f"You've clicked {str(safe_click())} times")

@output
@render.ui
def unsafe():
req(input.unsafe())
Expand All @@ -38,7 +36,6 @@ def _():
print("unsafe clicks:", input.unsafe())
# raise Exception("Observer exception: this should cause a crash")

@output
@render.ui
def txt_out():
req(input.txt(), cancel_output=True)
Expand Down
7 changes: 0 additions & 7 deletions examples/static_plots/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def fake_data():
cov = [(input.var(), input.cov()), (input.cov(), 1 / input.var())]
return rng.multivariate_normal(mean, cov, n).T

@output
@render.plot
def seaborn():
x, y = fake_data()
Expand All @@ -72,7 +71,6 @@ def seaborn():
sns.kdeplot(x=x, y=y, levels=5, color="w", linewidths=1)
return f

@output
@render.plot
def plotnine():
from plotnine import (
Expand All @@ -97,7 +95,6 @@ def plotnine():
+ theme(legend_position="top")
)

@output
@render.plot
def pandas():
ts = pd.Series(
Expand All @@ -106,7 +103,6 @@ def pandas():
ts = ts.cumsum()
return ts.plot()

@output
@render.plot
def holoviews():
import holoviews as hv
Expand All @@ -115,7 +111,6 @@ def holoviews():
links = pd.DataFrame(les_mis["links"])
return hv.render(hv.Chord(links), backend="matplotlib")

@output
@render.plot
def xarray():
import xarray as xr
Expand All @@ -126,7 +121,6 @@ def xarray():
air.attrs["units"] = "deg C"
return air.isel(lon=10, lat=[19, 21, 22]).plot.line(x="time")

@output
@render.plot
def geopandas():
import geodatasets
Expand All @@ -138,7 +132,6 @@ def geopandas():
boros.sort_index(inplace=True)
return boros.plot()

@output
@render.plot
def missingno():
import matplotlib.pyplot as plt
Expand Down
3 changes: 0 additions & 3 deletions examples/typed_inputs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,18 @@ 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.
@output
@render.text
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.
@output
@render.text
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.
@output
@render.text
async def txt3():
return str(input.n2() * 2)
Expand Down
1 change: 0 additions & 1 deletion examples/ui-func/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def app_ui(request: Request):


def server(input: Inputs, output: Outputs, session: Session):
@output
@render.text
def now():
reactive.invalidate_later(0.1)
Expand Down
1 change: 0 additions & 1 deletion shiny/api-examples/Calc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def second():
input.second()
return random.randint(1, 1000)

@output
@render.ui
def result():
return first() + second()
Expand Down
1 change: 0 additions & 1 deletion shiny/api-examples/Module/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def counter_server(
def _():
count.set(count() + 1)

@output
@render.text
def out() -> str:
return f"Click count is {count()}"
Expand Down
1 change: 0 additions & 1 deletion shiny/api-examples/Progress/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


def server(input: Inputs, output: Outputs, session: Session):
@output
@render.text
@reactive.event(input.button)
async def compute():
Expand Down
2 changes: 0 additions & 2 deletions shiny/api-examples/SafeException/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@


def server(input: Inputs, output: Outputs, session: Session):
@output
@render.ui
def safe():
raise SafeException("This is a safe exception")

@output
@render.ui
def unsafe():
raise Exception("This is an unsafe exception")
Expand Down
1 change: 0 additions & 1 deletion shiny/api-examples/SilentCancelOutputException/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


def server(input: Inputs, output: Outputs, session: Session):
@output
@render.ui
def txt_out():
if not input.txt():
Expand Down
1 change: 0 additions & 1 deletion shiny/api-examples/SilentException/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


def server(input: Inputs, output: Outputs, session: Session):
@output
@render.ui
def txt_out():
if not input.txt():
Expand Down
Loading