Skip to content

Commit 3944a6d

Browse files
committed
Remove @output and session from server where possible
1 parent 876560a commit 3944a6d

File tree

106 files changed

+204
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+204
-308
lines changed

examples/airmass/app.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from astropy.coordinates import AltAz, EarthLocation, SkyCoord
1313
from location import location_server, location_ui
1414

15-
from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
15+
from shiny import App, Inputs, reactive, render, req, ui
1616

1717
app_ui = ui.page_fixed(
1818
ui.tags.h3("Air mass calculator"),
@@ -57,7 +57,7 @@
5757
)
5858

5959

60-
def server(input: Inputs, output: Outputs, session: Session):
60+
def server(input: Inputs):
6161
loc = location_server("location")
6262
time_padding = datetime.timedelta(hours=1.5)
6363

@@ -119,7 +119,6 @@ def df() -> Dict[str, pd.DataFrame]:
119119
for (altaz, obj) in zip(altaz_list, obj_names())
120120
}
121121

122-
@output
123122
@render.plot
124123
def plot():
125124
fig, [ax1, ax2] = plt.subplots(nrows=2)
@@ -160,12 +159,10 @@ def add_boundary(ax, xval):
160159

161160
return fig
162161

163-
@output
164162
@render.table
165163
def table() -> pd.DataFrame:
166164
return pd.concat(df())
167165

168-
@output
169166
@render.ui
170167
def timeinfo():
171168
start_utc, end_utc = times_utc()

examples/brownian/app.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
)
4242

4343

44-
def server(input, output, session):
44+
def server(input):
4545
# BROWNIAN MOTION ====
4646

4747
@reactive.Calc
@@ -85,22 +85,18 @@ def update_plotly_camera():
8585

8686
# DEBUGGING ====
8787

88-
@output
8988
@render.text
9089
def x_debug():
9190
return camera_eye()["x"]
9291

93-
@output
9492
@render.text
9593
def y_debug():
9694
return camera_eye()["y"]
9795

98-
@output
9996
@render.text
10097
def z_debug():
10198
return camera_eye()["z"]
10299

103-
@output
104100
@render.text
105101
def mag_debug():
106102
eye = camera_eye()

examples/cpuinfo/app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import numpy as np
1414
import pandas as pd
1515

16-
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
16+
from shiny import App, Inputs, reactive, render, ui
1717

1818
# The agg matplotlib backend seems to be a little more efficient than the default when
1919
# running on macOS, and also gives more consistent results across operating systems
@@ -108,7 +108,7 @@ def cpu_current():
108108
return cpu_percent(percpu=True)
109109

110110

111-
def server(input: Inputs, output: Outputs, session: Session):
111+
def server(input: Inputs):
112112
cpu_history = reactive.Value(None)
113113

114114
@reactive.Calc
@@ -145,7 +145,6 @@ def collect_cpu_samples():
145145
def reset_history():
146146
cpu_history.set(None)
147147

148-
@output
149148
@render.plot
150149
def plot():
151150
history = cpu_history_with_hold()
@@ -205,7 +204,6 @@ def plot():
205204

206205
return fig
207206

208-
@output
209207
@render.table
210208
def table():
211209
history = cpu_history_with_hold()

examples/dataframe/app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import seaborn as sns
33
from shinyswatch.theme import darkly
44

5-
from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
5+
from shiny import App, Inputs, reactive, render, req, ui
66

77

88
def app_ui(req):
@@ -54,14 +54,13 @@ def light_dark_switcher(dark):
5454
)
5555

5656

57-
def server(input: Inputs, output: Outputs, session: Session):
57+
def server(input: Inputs):
5858
df: reactive.Value[pd.DataFrame] = reactive.Value()
5959

6060
@reactive.Effect
6161
def update_df():
6262
return df.set(sns.load_dataset(req(input.dataset())))
6363

64-
@output
6564
@render.data_frame
6665
def grid():
6766
height = 350
@@ -91,7 +90,6 @@ def handle_edit():
9190
df_copy.iat[edit["row"], edit["col"]] = edit["new_value"]
9291
df.set(df_copy)
9392

94-
@output
9593
@render.text
9694
def detail():
9795
if (

examples/duckdb/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def load_csv(con, csv_name, table_name):
6666
)
6767

6868

69-
def server(input, output, session):
69+
def server(input):
7070
mod_counter = reactive.Value(0)
7171

7272
query_output_server("initial_query", con=con, remove_id="initial_query")

examples/event/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22

3-
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
3+
from shiny import App, Inputs, reactive, render, ui
44

55
app_ui = ui.page_fluid(
66
ui.tags.p(
@@ -26,7 +26,7 @@
2626
)
2727

2828

29-
def server(input: Inputs, output: Outputs, session: Session):
29+
def server(input: Inputs):
3030
@reactive.Effect
3131
@reactive.event(input.btn)
3232
def _():
@@ -66,7 +66,6 @@ async def _():
6666
val = await btn_async_r()
6767
print("async @calc() event: ", str(val))
6868

69-
@output
7069
@render.ui
7170
@reactive.event(btn_async_r)
7271
async def btn_async_value():

examples/global_pyplot/app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import matplotlib.pyplot as plt
22

3-
from shiny import App, Inputs, Outputs, Session, render, ui
3+
from shiny import App, Inputs, render, ui
44

55
app_ui = ui.page_fluid(
66
ui.input_checkbox("render", "Render", value=True),
@@ -18,14 +18,12 @@
1818
)
1919

2020

21-
def server(input: Inputs, output: Outputs, session: Session):
22-
@output
21+
def server(input: Inputs):
2322
@render.plot
2423
def mpl():
2524
if input.render():
2625
plt.hist([1, 1, 2, 3, 5])
2726

28-
@output
2927
@render.plot
3028
async def mpl_bad():
3129
if input.render():

examples/headers/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
def server(input: Inputs, output: Outputs, session: Session):
12-
@output
1312
@render.text
1413
def headers():
1514
s = ""
@@ -18,7 +17,6 @@ def headers():
1817

1918
return s
2019

21-
@output
2220
@render.text
2321
def user_groups():
2422
return f"session.user: {session.user}\nsession.groups: {session.groups}"

examples/inputs-update/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import date
22

3-
from shiny import App, Inputs, Outputs, Session, reactive, ui
3+
from shiny import App, Inputs, reactive, ui
44

55
app_ui = ui.page_fluid(
66
ui.panel_title("Changing the values of inputs from the server"),
@@ -87,7 +87,7 @@
8787
)
8888

8989

90-
def server(input: Inputs, output: Outputs, session: Session):
90+
def server(input: Inputs):
9191
@reactive.Effect
9292
def _():
9393
# We'll use these multiple times, so use short var names for

examples/load_balance/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131

3232
def server(input: Inputs, output: Outputs, session: Session):
33-
@output
3433
@render.ui
3534
def out():
3635
# Register a dynamic route for the client to try to connect to.

examples/model-score/app.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from plotly_streaming import render_plotly_streaming
1010
from shinywidgets import output_widget
1111

12-
from shiny import App, Inputs, Outputs, Session, reactive, render, ui
12+
from shiny import App, Inputs, reactive, render, ui
1313

1414
THRESHOLD_MID = 0.85
1515
THRESHOLD_MID_COLOR = "rgb(0, 137, 26)"
@@ -133,7 +133,7 @@ def app_ui(req):
133133
)
134134

135135

136-
def server(input: Inputs, output: Outputs, session: Session):
136+
def server(input: Inputs):
137137
@reactive.Calc
138138
def recent_df():
139139
"""
@@ -178,7 +178,6 @@ def filtered_df():
178178
def filtered_model_names():
179179
return filtered_df()["model"].unique()
180180

181-
@output
182181
@render.ui
183182
def value_boxes():
184183
data = filtered_df()
@@ -208,7 +207,6 @@ def value_boxes():
208207
fixed_width=True,
209208
)
210209

211-
@output
212210
@render_plotly_streaming(recreate_key=filtered_model_names, update="data")
213211
def plot_timeseries():
214212
"""
@@ -249,7 +247,6 @@ def plot_timeseries():
249247

250248
return fig
251249

252-
@output
253250
@render_plotly_streaming(recreate_key=filtered_model_names, update="data")
254251
def plot_dist():
255252
fig = px.histogram(

examples/moduleapp/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ def dynamic_counter():
6262
)
6363

6464

65-
def server(input: Inputs, output: Outputs, session: Session):
65+
def server(input: Inputs):
6666
counter_server("counter1")
6767
counter_wrapper_server("counter2_wrapper", "Counter 2")
6868

69-
@output()
7069
@render.ui()
7170
def counter3_ui():
7271
counter_server("counter3")

examples/penguins/app.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import seaborn as sns
99
from colors import bg_palette, palette
1010

11-
import shiny.experimental as x
12-
from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
11+
from shiny import App, Inputs, reactive, render, req, ui
1312

1413
sns.set_theme()
1514

@@ -48,7 +47,7 @@
4847
)
4948

5049

51-
def server(input: Inputs, output: Outputs, session: Session):
50+
def server(input: Inputs):
5251
@reactive.Calc
5352
def filtered_df() -> pd.DataFrame:
5453
"""Returns a Pandas data frame that includes only the desired rows"""
@@ -59,7 +58,6 @@ def filtered_df() -> pd.DataFrame:
5958
# Filter the rows so we only include the desired species
6059
return df[df["Species"].isin(input.species())]
6160

62-
@output
6361
@render.plot
6462
def scatter():
6563
"""Generates a plot for Shiny to display to the user"""
@@ -77,13 +75,12 @@ def scatter():
7775
legend=False,
7876
)
7977

80-
@output
8178
@render.ui
8279
def value_boxes():
8380
df = filtered_df()
8481

8582
def penguin_value_box(title: str, count: int, bgcol: str, showcase_img: str):
86-
return x.ui.value_box(
83+
return ui.value_box(
8784
title,
8885
count,
8986
{"class": "pt-1 pb-0"},
@@ -120,7 +117,7 @@ def penguin_value_box(title: str, count: int, bgcol: str, showcase_img: str):
120117
if name in input.species()
121118
]
122119

123-
return ui.layout_column_wrap(1 / len(value_boxes), *value_boxes)
120+
return ui.layout_column_wrap(*value_boxes, width=1 / len(value_boxes))
124121

125122

126123
app = App(

examples/req/app.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from shiny import App, Inputs, Outputs, Session, reactive, render, req, ui
1+
from shiny import App, Inputs, reactive, render, req, ui
22
from shiny.types import SafeException
33

44
app_ui = ui.page_fluid(
@@ -15,18 +15,16 @@
1515
)
1616

1717

18-
def server(input: Inputs, output: Outputs, session: Session):
18+
def server(input: Inputs):
1919
@reactive.Calc
2020
def safe_click():
2121
req(input.safe())
2222
return input.safe()
2323

24-
@output
2524
@render.ui
2625
def safe():
2726
raise SafeException(f"You've clicked {str(safe_click())} times")
2827

29-
@output
3028
@render.ui
3129
def unsafe():
3230
req(input.unsafe())
@@ -38,7 +36,6 @@ def _():
3836
print("unsafe clicks:", input.unsafe())
3937
# raise Exception("Observer exception: this should cause a crash")
4038

41-
@output
4239
@render.ui
4340
def txt_out():
4441
req(input.txt(), cancel_output=True)

0 commit comments

Comments
 (0)