animate: Animate a widget field

View source: R/animation.R

animateR Documentation

Animate a widget field

Description

Changes a numeric field of a widget (e.g. value of a progress_bar(), offset_y of a scroll_view(), count of a custom widget) smoothly from its current value to to. Starting a new animation of the same field replaces the running one. Animations stop when the widget is removed or the app exits.

Usage

animate(
  widget,
  property,
  to,
  duration = 0.3,
  easing = "out_cubic",
  from = NULL,
  on_complete = NULL
)

Arguments

widget

A widget attached to a running app.

property

Name of a numeric field.

to

Target value.

duration

Seconds.

easing

"linear", "in_quad", "out_quad", "in_out_quad", "in_cubic", "out_cubic" (default) or "in_out_cubic".

from

Start value (default: the current value).

on_complete

Optional ⁠function(widget, app)⁠.

Value

An Animation handle with cancel().

Examples

bar <- progress_bar(id = "progress")
pilot <- test_app(app(bar), width = 30, height = 1)
animate(pilot$query_one("#progress"), "value", to = 1, duration = 0.5)
pilot$advance(1)
bar$value
pilot$stop()

termr documentation built on Oct. 21, 2026, 5:13 p.m.