panel.io package#

Submodules#

Module contents#

The io module contains utilities for loading JS components, embedding model state, and rendering panel objects.

class panel.io.PeriodicCallback(*, callback, count, counter, log, period, running, timeout, name)[source]#

Bases: Parameterized

Periodic encapsulates a periodic callback which will run both in tornado based notebook environments and on bokeh server. By default the callback will run until the stop method is called, but count and timeout values can be set to limit the number of executions or the maximum length of time for which the callback will run. The callback may also be started and stopped by setting the running parameter to True or False respectively.

Methods

start()

Starts running the periodic callback.

stop()

Stops running the periodic callback.

Parameter Definitions


callback = Callable(allow_None=True, label='Callback')

The callback to execute periodically.

counter = Integer(default=0, inclusive_bounds=(True, True), label='Counter')

Counts the number of executions.

count = Integer(allow_None=True, inclusive_bounds=(True, True), label='Count')

Number of times the callback will be executed, by default this is unlimited.

log = Boolean(default=True, label='Log')

Whether the periodic callback should log its actions.

period = Integer(default=500, inclusive_bounds=(True, True), label='Period')

Period in milliseconds at which the callback is executed.

timeout = Integer(allow_None=True, inclusive_bounds=(True, True), label='Timeout')

Timeout in milliseconds from the start time at which the callback expires.

running = Boolean(default=False, label='Running')

Toggles whether the periodic callback is currently running.

start()[source]#

Starts running the periodic callback.

stop()[source]#

Stops running the periodic callback.

class panel.io.Resources(*args, absolute=False, notebook=False, **kwargs)[source]#

Bases: Resources

adjust_paths(resources)[source]#

Computes relative and absolute paths for resources.

clone(*, components=None) Resources[source]#

Make a clone of a resources instance allowing to override its components.

extra_resources(resources, resource_type)[source]#

Adds resources for ReactiveHTML components.

panel.io.hold(doc: Document | None = None, policy: HoldPolicyType = 'combine', comm: Comm | None = None)[source]#

Context manager that holds events on a particular Document allowing them all to be collected and dispatched when the context manager exits. This allows multiple events on the same object to be combined if the policy is set to ‘combine’.

Parameters:
doc: Document

The Bokeh Document to hold events on.

policy: HoldPolicyType

One of ‘combine’, ‘collect’ or None determining whether events setting the same property are combined or accumulated to be dispatched when the context manager exits.

comm: Comm

The Comm to dispatch events on when the context manager exits.

panel.io.immediate_dispatch(doc: Document | None = None)[source]#

Context manager to trigger immediate dispatch of events triggered inside the execution context even when Document events are currently on hold.

Parameters:
doc: Document

The document to dispatch events on (if None then state.curdoc is used).

panel.io.ipywidget(obj: Any, doc=None, **kwargs: Any)[source]#

Returns an ipywidget model which renders the Panel object.

Requires jupyter_bokeh to be installed.

Parameters:
obj: object

Any Panel object or object which can be rendered with Panel

doc: bokeh.Document

Bokeh document the bokeh model will be attached to.

**kwargs: dict

Keyword arguments passed to the pn.panel utility function

Returns:
Returns an ipywidget model which renders the Panel object.
panel.io.profile(name: str, engine: ProfilingEngine = 'pyinstrument') Callable[[Callable[_P, _R]], Callable[_P, _R]][source]#

A decorator which may be added to any function to record profiling output.

Parameters:
name: str

A unique name for the profiling session.

engine: str

The profiling engine, e.g. ‘pyinstrument’, ‘snakeviz’ or ‘memray’

panel.io.push(doc: Document, comm: Comm, binary: bool = True, msg: Message | None = None) None[source]#

Pushes events stored on the document across the provided comm.

panel.io.push_notebook(*objs: Viewable) None[source]#

A utility for pushing updates to the frontend given a Panel object. This is required when modifying any Bokeh object directly in a notebook session.

Parameters:
objs: panel.viewable.Viewable
panel.io.serve(panels: TViewableFuncOrPath | dict[str, TViewableFuncOrPath], port: int = 0, address: str | None = None, websocket_origin: str | list[str] | None = None, loop: IOLoop | None = None, show: bool = True, start: bool = True, title: str | None = None, verbose: bool = True, location: bool = True, threaded: bool = False, admin: bool = False, **kwargs) StoppableThread | Server[source]#

Allows serving one or more panel objects on a single server. The panels argument should be either a Panel object or a function returning a Panel object or a dictionary of these two. If a dictionary is supplied the keys represent the slugs at which each app is served, e.g. serve({‘app’: panel1, ‘app2’: panel2}) will serve apps at /app and /app2 on the server.

Reference: https://panel.holoviz.org/user_guide/Server_Configuration.html#serving-multiple-apps

Parameters:
panels: Viewable, function or {str: Viewable or function}

A Panel object, a function returning a Panel object or a dictionary mapping from the URL slug to either.

port: int (optional, default=0)

Allows specifying a specific port

addressstr

The address the server should listen on for HTTP requests.

websocket_origin: str or list(str) (optional)

A list of hosts that can connect to the websocket.

This is typically required when embedding a server app in an external web site.

If None, “localhost” is used.

looptornado.ioloop.IOLoop (optional, default=IOLoop.current())

The tornado IOLoop to run the Server on

showboolean (optional, default=True)

Whether to open the server in a new browser tab on start

startboolean(optional, default=True)

Whether to start the Server

title: str or {str: str} (optional, default=None)

An HTML title for the application or a dictionary mapping from the URL slug to a customized title

verbose: boolean (optional, default=True)

Whether to print the address and port

locationboolean or panel.io.location.Location

Whether to create a Location component to observe and set the URL location.

threaded: boolean (default=False)

Whether to start the server on a new Thread

admin: boolean (default=False)

Whether to enable the admin panel

kwargs: dict

Additional keyword arguments to pass to Server instance

panel.io.unlocked(policy: HoldPolicyType = 'combine') Iterator[source]#

Context manager which unlocks a Document and dispatches ModelChangedEvents triggered in the context body to all sockets on current sessions.

Parameters:
policy: Literal[‘combine’ | ‘collect’]

One of ‘combine’ or ‘collect’ determining whether events setting the same property are combined or accumulated to be dispatched when the context manager exits.

panel.io.with_lock(func: Callable) Callable[source]#

Wrap a callback function to execute with a lock allowing the function to modify bokeh models directly.

Parameters:
func: callable

The callable to wrap

Returns:
wrapper: callable

Function wrapped to execute without a Document lock.