import panel as pn pn.extension()
DiscretePlayer widget displays media-player-like controls that allow playing and stepping through the provided options. When playing it triggers events at a pre-defined interval on the frontend, advancing the player value each time. It falls into the broad category of single-value, option-selection widgets that provide a compatible API and include the
For layout and styling related parameters see the customization user guide.
direction(int): Current play direction of the Player (-1: playing in reverse, 0: paused, 1: playing).
interval(int): Interval in milliseconds between updates
loop_policy(str): Looping policy; must be one of ‘once’, ‘loop’, or ‘reflect’
options(list or dict): A list or dictionary of options to select from
value(object): The current value; must be one of the option values
value_throttled(object): The current value throttled until mouseup (when selected using slider)
disabled(boolean): Whether the widget is editable
name(str): The title of the widget
show_loop_controls(boolean): Whether radio buttons allowing to switch between loop policies options are shown
The widget has a number of buttons to go to the first or last value, step forward or backward, and play and pause the widget. It also provides control over the
loop_policy, which determines whether to play ‘once’, ‘loop’, or ‘reflect’. Additionally
+ buttons slow down and speed up the player speed.
discrete_player = pn.widgets.DiscretePlayer(name='Discrete Player', options=[2, 4, 8, 16, 32, 64, 128], value=8, loop_policy='loop') discrete_player
Like most other widgets,
DiscretePlayer has a value parameter that can be accessed or set:
DiscretePlayer can be controlled programmatically using the
direction parameter which has three possible states:
-1: playing in reverse
Alternatively it can be controlled via the
import time discrete_player.play() time.sleep(2) discrete_player.reverse() time.sleep(2) discrete_player.pause()