Skip to content
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* The sidebar's collapse toggle now has a high `z-index` value to ensure it always appears above elements in the main content area of `ui.layout_sidebar()`. The sidebar overlay also now receives the same high `z-index` on mobile layouts. (#1129)

* Updated example apps to use lower-case versions of `reactive.Calc`->`reactive.calc`, `reactive.Effect`->`reactive.effect`, and `reactive.Value`->`reactive.value`. (#1164)

### Bug fixes

* Fixed `input_task_button` not working in a Shiny module. (#1108)
Expand Down
12 changes: 6 additions & 6 deletions examples/airmass/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ def server(input: Inputs, output: Outputs, session: Session):
loc = location_server("location")
time_padding = datetime.timedelta(hours=1.5)

@reactive.Calc
@reactive.calc
def obj_names() -> List[str]:
"""Returns a split and *slightly* cleaned-up list of object names"""
req(input.objects())
return [x.strip() for x in input.objects().split(",") if x.strip() != ""]

@reactive.Calc
@reactive.calc
def obj_coords() -> List[SkyCoord]:
return [SkyCoord.from_name(name) for name in obj_names()]

@reactive.Calc
@reactive.calc
def times_utc() -> Tuple[datetime.datetime, datetime.datetime]:
req(input.date())
lat, long = loc()
Expand All @@ -81,18 +81,18 @@ def times_utc() -> Tuple[datetime.datetime, datetime.datetime]:
sun.get_sunrise_time(input.date() + datetime.timedelta(days=1)),
)

@reactive.Calc
@reactive.calc
def timezone() -> Optional[str]:
lat, long = loc()
return timezonefinder.TimezoneFinder().timezone_at(lat=lat, lng=long)

@reactive.Calc
@reactive.calc
def times_at_loc():
start, end = times_utc()
tz = pytz.timezone(timezone())
return (start.astimezone(tz), end.astimezone(tz))

@reactive.Calc
@reactive.calc
def df() -> Dict[str, pd.DataFrame]:
start, end = times_at_loc()
times = pd.date_range(
Expand Down
8 changes: 4 additions & 4 deletions examples/airmass/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,24 @@ def on_map_interaction(**kwargs):

register_widget("map", map)

@reactive.Effect
@reactive.effect
def _():
coords = reactive_read(marker, "location")
if coords:
update_text_inputs(coords[0], coords[1])

@reactive.Effect
@reactive.effect
def sync_autolocate():
coords = input.here()
ui.notification_remove("searching")
if coords and not input.lat() and not input.long():
update_text_inputs(coords["latitude"], coords["longitude"])

@reactive.Effect
@reactive.effect
def sync_inputs_to_marker():
update_marker(input.lat(), input.long())

@reactive.Calc
@reactive.calc
def location():
"""Returns tuple of (lat,long) floats--or throws silent error if no lat/long is
selected"""
Expand Down
6 changes: 3 additions & 3 deletions examples/annotation-export/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@


def server(input: Inputs, output: Outputs, session: Session):
annotated_data = reactive.Value(weather_df)
annotated_data = reactive.value(weather_df)

@reactive.Calc
@reactive.calc
def selected_data():
out = brushed_points(annotated_data(), input.time_series_brush(), xvar="date")
return out

@reactive.Effect
@reactive.effect
@reactive.event(input.annotate_button)
def _():
selected = selected_data()
Expand Down
12 changes: 6 additions & 6 deletions examples/brownian/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
def server(input, output, session):
# BROWNIAN MOTION ====

@reactive.Calc
@reactive.calc
def random_walk():
"""Generates brownian data whenever 'New Data' is clicked"""
input.data_btn()
Expand All @@ -54,7 +54,7 @@ def random_walk():
widget = brownian_widget(600, 600)
register_widget("plot", widget)

@reactive.Effect
@reactive.effect
def update_plotly_data():
walk = random_walk()
layer = widget.data[0]
Expand All @@ -65,7 +65,7 @@ def update_plotly_data():

# HAND TRACKING ====

@reactive.Calc
@reactive.calc
def camera_eye():
"""The eye position, as reflected by the hand input"""
hand_val = input.hand()
Expand All @@ -78,7 +78,7 @@ def camera_eye():
# The raw data is a little jittery. Smooth it out by averaging a few samples
smooth_camera_eye = reactive_smooth(n_samples=5, smoother=xyz_mean)(camera_eye)

@reactive.Effect
@reactive.effect
def update_plotly_camera():
"""Update Plotly camera using the hand tracking"""
widget.layout.scene.camera.eye = smooth_camera_eye()
Expand Down Expand Up @@ -112,9 +112,9 @@ def reactive_smooth(n_samples, smoother, *, filter_none=True):

def wrapper(calc):
buffer = [] # Ring buffer of capacity `n_samples`
result = reactive.Value(None) # Holds the most recent smoothed result
result = reactive.value(None) # Holds the most recent smoothed result

@reactive.Effect
@reactive.effect
def _():
# Get latest value. Because this is happening in a reactive Effect, we'll
# automatically take a reactive dependency on whatever is happening in the
Expand Down
8 changes: 4 additions & 4 deletions examples/cpuinfo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@
)


@reactive.Calc
@reactive.calc
def cpu_current():
reactive.invalidate_later(SAMPLE_PERIOD)
return cpu_percent(percpu=True)


def server(input: Inputs, output: Outputs, session: Session):
cpu_history = reactive.Value(None)
cpu_history = reactive.value(None)

@reactive.Calc
@reactive.calc
def cpu_history_with_hold():
# If "hold" is on, grab an isolated snapshot of cpu_history; if not, then do a
# regular read
Expand All @@ -123,7 +123,7 @@ def cpu_history_with_hold():
with reactive.isolate():
return cpu_history()

@reactive.Effect
@reactive.effect
def collect_cpu_samples():
"""cpu_percent() reports just the current CPU usage sample; this Effect gathers
them up and stores them in the cpu_history reactive value, in a numpy 2D array
Expand Down
6 changes: 3 additions & 3 deletions examples/dataframe/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def light_dark_switcher(dark):


def server(input: Inputs, output: Outputs, session: Session):
df: reactive.Value[pd.DataFrame] = reactive.Value()
df: reactive.value[pd.DataFrame] = reactive.value()

@reactive.Effect
@reactive.effect
def update_df():
return df.set(sns.load_dataset(req(input.dataset())))

Expand All @@ -82,7 +82,7 @@ def grid():
row_selection_mode=input.selection_mode(),
)

@reactive.Effect
@reactive.effect
@reactive.event(input.grid_cell_edit)
def handle_edit():
edit = input.grid_cell_edit()
Expand Down
8 changes: 4 additions & 4 deletions examples/duckdb/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def load_csv(con, csv_name, table_name):


def server(input, output, session):
mod_counter = reactive.Value(0)
mod_counter = reactive.value(0)

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

@reactive.Effect
@reactive.effect
@reactive.event(input.add_query)
def _():
counter = mod_counter.get() + 1
Expand All @@ -84,7 +84,7 @@ def _():
)
query_output_server(id, con=con, remove_id=id)

@reactive.Effect
@reactive.effect
@reactive.event(input.show_meta)
def _():
counter = mod_counter.get() + 1
Expand All @@ -99,7 +99,7 @@ def _():
)
query_output_server(id, con=con, remove_id=id)

@reactive.Effect
@reactive.effect
@reactive.event(input.rmv)
def _():
ui.remove_ui(selector="div:has(> #txt)")
Expand Down
2 changes: 1 addition & 1 deletion examples/duckdb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def results():

return result

@reactive.Effect
@reactive.effect
@reactive.event(input.rmv)
def _():
ui.remove_ui(selector=f"div#{remove_id}")
12 changes: 6 additions & 6 deletions examples/event/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@


def server(input: Inputs, output: Outputs, session: Session):
@reactive.Effect
@reactive.effect
@reactive.event(input.btn)
def _():
print("@effect() event: ", str(input.btn()))

@reactive.Calc
@reactive.calc
@reactive.event(input.btn)
def btn() -> int:
return input.btn()

@reactive.Effect
@reactive.effect
def _():
print("@calc() event: ", str(btn()))

Expand All @@ -49,19 +49,19 @@ def btn_value():
# -----------------------------------------------------------------------------
# Async
# -----------------------------------------------------------------------------
@reactive.Effect
@reactive.effect
@reactive.event(input.btn_async)
async def _():
await asyncio.sleep(0)
print("async @effect() event: ", str(input.btn_async()))

@reactive.Calc
@reactive.calc
@reactive.event(input.btn_async)
async def btn_async_r() -> int:
await asyncio.sleep(0)
return input.btn_async()

@reactive.Effect
@reactive.effect
async def _():
val = await btn_async_r()
print("async @calc() event: ", str(val))
Expand Down
2 changes: 1 addition & 1 deletion examples/express/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# This reactive value can be used by multiple sessions; if it is invalidated (in
# other words, if the value is changed), it will trigger invalidations in all of
# those sessions.
rv = reactive.Value(50)
rv = reactive.value(50)
2 changes: 1 addition & 1 deletion examples/express/shared_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def histogram():
ui.input_slider("n", "N", 1, 100, 50)


@reactive.Effect
@reactive.effect
def _():
shared.rv.set(input.n())

Expand Down
2 changes: 1 addition & 1 deletion examples/inputs-update/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@


def server(input: Inputs, output: Outputs, session: Session):
@reactive.Effect
@reactive.effect
def _():
# We'll use these multiple times, so use short var names for
# convenience.
Expand Down
10 changes: 5 additions & 5 deletions examples/model-score/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def app_ui(req):


def server(input: Inputs, output: Outputs, session: Session):
@reactive.Calc
@reactive.calc
def recent_df():
"""
Returns the most recent rows from the database, at the refresh interval
Expand All @@ -152,7 +152,7 @@ def recent_df():
with reactive.isolate():
return df()

@reactive.Calc
@reactive.calc
def timeframe_df():
"""
Returns rows from the database within the specified time range. Notice that we
Expand All @@ -162,7 +162,7 @@ def timeframe_df():
start, end = input.timerange()
return read_time_period(start, end)

@reactive.Calc
@reactive.calc
def filtered_df():
"""
Return the data frame that should be displayed in the app, based on the user's
Expand All @@ -174,7 +174,7 @@ def filtered_df():
# Filter the rows so we only include the desired models
return data[data["model"].isin(input.models())]

@reactive.Calc
@reactive.calc
def filtered_model_names():
return filtered_df()["model"].unique()

Expand Down Expand Up @@ -282,7 +282,7 @@ def plot_dist():

return fig

@reactive.Effect
@reactive.effect
def update_time_range():
"""
Every 5 seconds, update the custom time range slider's min and max values to
Expand Down
8 changes: 4 additions & 4 deletions examples/model-score/plotly_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def wrapper():
fig = func()
widget = go.FigureWidget(fig)

@reactive.Effect
@reactive.effect
def update_plotly_data():
f_new = func()
with widget.batch_update():
Expand All @@ -83,16 +83,16 @@ def update_plotly_data():

def deduplicate(func):
with reactive.isolate():
rv = reactive.Value(func())
rv = reactive.value(func())

@reactive.Effect
@reactive.effect
def update():
x = func()
with reactive.isolate():
if x != rv():
rv.set(x)

@reactive.Calc
@reactive.calc
@functools.wraps(func)
def wrapper():
return rv()
Expand Down
4 changes: 2 additions & 2 deletions examples/moduleapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def counter_ui(label: str = "Increment counter") -> ui.TagChild:
def counter_server(
input: Inputs, output: Outputs, session: Session, starting_value: int = 0
):
count: reactive.Value[int] = reactive.Value(starting_value)
count: reactive.value[int] = reactive.value(starting_value)

@reactive.Effect
@reactive.effect
@reactive.event(input.button)
def _():
count.set(count() + 1)
Expand Down
Loading