viewable Module

viewable Module

Defines the Viewable and Reactive baseclasses allow all panel objects to display themselves, communicate with a Python process and react in response to changes to parameters and the underlying bokeh models.

class panel.viewable.Layoutable(**params)[source]

Bases: param.parameterized.Parameterized

align = param.ObjectSelector(default=’start’, objects=[‘start’, ‘end’, ‘center’])

Whether the object should be aligned with the start, end or center of its container

aspect_ratio = param.Parameter()

Describes the proportional relationship between component’s width and height. This works if any of component’s dimensions are flexible in size. If set to a number, width / height =         aspect_ratio relationship will be maintained. Otherwise, if set to "auto", component’s preferred width and height will be used to determine the aspect (if not set, no aspect will be preserved).

background = param.Parameter()

Background color of the component.

css_classes = param.List(bounds=(0, None))

CSS classes to apply to the layout.

width = param.Integer(bounds=(0, None), inclusive_bounds=(True, True))

The width of the component (in pixels). This can be either fixed or preferred width, depending on width sizing policy.

height = param.Integer(bounds=(0, None), inclusive_bounds=(True, True))

The height of the component (in pixels). This can be either fixed or preferred height, depending on height sizing policy.

min_width = param.Integer(bounds=(0, None), inclusive_bounds=(True, True))

Minimal width of the component (in pixels) if width is adjustable.

min_height = param.Integer(bounds=(0, None), inclusive_bounds=(True, True))

Minimal height of the component (in pixels) if height is adjustable.

max_width = param.Integer(bounds=(0, None), inclusive_bounds=(True, True))

Minimal width of the component (in pixels) if width is adjustable.

max_height = param.Integer(bounds=(0, None), inclusive_bounds=(True, True))

Minimal height of the component (in pixels) if height is adjustable.

margin = param.Parameter(default=5)

Allows to create additional space around the component. May be specified as a two-tuple of the form (vertical, horizontal) or a four-tuple (top, right, bottom, left).

width_policy = param.ObjectSelector(default=’auto’, objects=[‘auto’, ‘fixed’, ‘fit’, ‘min’, ‘max’])

Describes how the component should maintain its width. "auto" Use component’s preferred sizing policy. "fixed" Use exactly width pixels. Component will overflow if it can’t fit in the available horizontal space. "fit" Use component’s preferred width (if set) and allow it to fit into the available horizontal space within the minimum and maximum width bounds (if set). Component’s width neither will be aggressively minimized nor maximized. "min" Use as little horizontal space as possible, not less than the minimum width (if set). The starting point is the preferred width (if set). The width of the component may shrink or grow depending on the parent layout, aspect management and other factors. "max" Use as much horizontal space as possible, not more than the maximum width (if set). The starting point is the preferred width (if set). The width of the component may shrink or grow depending on the parent layout, aspect management and other factors.

height_policy = param.ObjectSelector(default=’auto’, objects=[‘auto’, ‘fixed’, ‘fit’, ‘min’, ‘max’])

Describes how the component should maintain its height. "auto" Use component’s preferred sizing policy. "fixed" Use exactly height pixels. Component will overflow if it can’t fit in the available vertical space. "fit" Use component’s preferred height (if set) and allow to fit into the available vertical space within the minimum and maximum height bounds (if set). Component’s height neither will be aggressively minimized nor maximized. "min" Use as little vertical space as possible, not less than the minimum height (if set). The starting point is the preferred height (if set). The height of the component may shrink or grow depending on the parent layout, aspect management and other factors. "max" Use as much vertical space as possible, not more than the maximum height (if set). The starting point is the preferred height (if set). The height of the component may shrink or grow depending on the parent layout, aspect management and other factors.

sizing_mode = param.ObjectSelector(objects=[‘fixed’, ‘stretch_width’, ‘stretch_height’, ‘stretch_both’, ‘scale_width’, ‘scale_height’, ‘scale_both’, None])

How the component should size itself. This is a high-level setting for maintaining width and height of the component. To gain more fine grained control over sizing, use width_policy, height_policy and aspect_ratio instead (those take precedence over sizing_mode). "fixed" Component is not responsive. It will retain its original width and height regardless of any subsequent browser window resize events. "stretch_width" Component will responsively resize to stretch to the available width, without maintaining any aspect ratio. The height of the component depends on the type of the component and may be fixed or fit to component’s contents. "stretch_height" Component will responsively resize to stretch to the available height, without maintaining any aspect ratio. The width of the component depends on the type of the component and may be fixed or fit to component’s contents. "stretch_both" Component is completely responsive, independently in width and height, and will occupy all the available horizontal and vertical space, even if this changes the aspect ratio of the component. "scale_width" Component will responsively resize to stretch to the available width, while maintaining the original or provided aspect ratio. "scale_height" Component will responsively resize to stretch to the available height, while maintaining the original or provided aspect ratio. "scale_both" Component will responsively resize to both the available width and height, while maintaining the original or provided aspect ratio.

panel.viewable.LinkWatcher

alias of panel.viewable.Watcher

class panel.viewable.Reactive(**params)[source]

Bases: panel.viewable.Viewable

Reactive is a Viewable object that also supports syncing between the objects parameters and the underlying bokeh model either via the defined pyviz_comms.Comm type or when using bokeh server.

In order to bi-directionally link parameters with bokeh model instances the _link_params and _link_props methods define callbacks triggered when either the parameter or bokeh property values change. Since there may not be a 1-to-1 mapping between parameter and the model property the _process_property_change and _process_param_change may be overridden to apply any necessary transformations.

Parameters inherited from:

panel.viewable.Layoutable: align, aspect_ratio, background, css_classes, width, height, min_width, min_height, max_width, max_height, margin, width_policy, height_policy, sizing_mode

add_periodic_callback(callback, period=500, count=None, timeout=None, start=True)[source]

Schedules a periodic callback to be run at an interval set by the period. Returns a PeriodicCallback object with the option to stop and start the callback.

Parameters
  • callback (callable) – Callable function to be executed at periodic interval.

  • period (int) – Interval in milliseconds at which callback will be executed.

  • count (int) – Maximum number of times callback will be invoked.

  • timeout (int) – Timeout in seconds when the callback should be stopped.

  • start (boolean (default=True)) – Whether to start callback immediately.

Returns

Return type

Return a PeriodicCallback object with start and stop methods.

app(notebook_url='localhost:8888', port=0)

Displays a bokeh server app inline in the notebook.

Parameters
  • notebook_url (str) – URL to the notebook server

  • port (int (optional, default=0)) – Allows specifying a specific port

clone(**params)

Makes a copy of the object sharing the same parameters.

Parameters

params (Keyword arguments override the parameters on the clone.) –

Returns

Return type

Cloned Viewable object

controls(parameters=[], jslink=True)[source]

Creates a set of widgets which allow manipulating the parameters on this instance. By default all parameters which support linking are exposed, but an explicit list of parameters can be provided.

Parameters
  • parameters (list(str)) – An explicit list of parameters to return controls for.

  • jslink (bool) – Whether to use jslinks instead of Python based links. This does not allow using all types of parameters.

Returns

Return type

A layout of the controls

embed(max_states=1000, max_opts=3, json=False, save_path='./', load_path=None, progress=True)

Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.

Parameters
  • max_states (int) – The maximum number of states to embed

  • max_opts (int) – The maximum number of states for a single widget

  • json (boolean (default=True)) – Whether to export the data to json files

  • save_path (str (default='./')) – The path to save json files to

  • load_path (str (default=None)) – The path or URL the json files will be loaded from.

  • progress (boolean (default=False)) – Whether to report progress

get_root(doc=None, comm=None)

Returns the root model and applies pre-processing hooks

Parameters
  • doc (bokeh.Document) – Bokeh document the bokeh model will be attached to.

  • comm (pyviz_comms.Comm) – Optional pyviz_comms when working in notebook

Returns

Return type

Returns the bokeh model corresponding to this panel object

jscallback(args={}, **callbacks)[source]

Allows defining a JS callback to be triggered when a property changes on the source object. The keyword arguments define the properties that trigger a callback and the JS code that gets executed.

Parameters
  • args (dict) – A mapping of objects to make available to the JS callback

  • **callbacks (dict) – A mapping between properties on the source model and the code to execute when that property changes

Returns

callback – The Callback which can be used to disable the callback.

Return type

Callback

Links properties on the source object to those on the target object in JS code. Supports two modes, either specify a mapping between the source and target model properties as keywords or provide a dictionary of JS code snippets which maps from the source parameter to a JS code snippet which is executed when the property changes.

Parameters
  • target (HoloViews object or bokeh Model or panel Viewable) – The target to link the value to.

  • code (dict) – Custom code which will be executed when the widget value changes.

  • bidirectional (boolean) – Whether to link source and target bi-directionally

  • **links (dict) – A mapping between properties on the source model and the target model property to link it to.

Returns

link – The GenericLink which can be used unlink the widget and the target model.

Return type

GenericLink

Links the parameters on this object to attributes on another object in Python. Supports two modes, either specify a mapping between the source and target object parameters as keywords or provide a dictionary of callbacks which maps from the source parameter to a callback which is triggered when the parameter changes.

Parameters
  • target (object) – The target object of the link.

  • callbacks (dict) – Maps from a parameter in the source object to a callback.

  • **links (dict) – Maps between parameters on this object to the parameters on the supplied object.

pprint()

Prints a compositional repr of the class.

save(filename, title=None, resources=None, template=None, template_variables=None, embed=False, max_states=1000, max_opts=3, embed_json=False, json_prefix='', save_path='./', load_path=None)

Saves Panel objects to file.

Parameters
  • filename (string or file-like object) – Filename to save the plot to

  • title (string) – Optional title for the plot

  • resources (bokeh resources) – One of the valid bokeh.resources (e.g. CDN or INLINE)

  • template – passed to underlying io.save

  • template_variables – passed to underlying io.save

  • embed (bool) – Whether the state space should be embedded in the saved file.

  • max_states (int) – The maximum number of states to embed

  • max_opts (int) – The maximum number of states for a single widget

  • embed_json (boolean (default=True)) – Whether to export the data to json files

  • json_prefix (str (default='')) – Prefix for the auto-generated json directory

  • save_path (str (default='./')) – The path to save json files to

  • load_path (str (default=None)) – The path or URL the json files will be loaded from.

select(selector=None)

Iterates over the Viewable and any potential children in the applying the Selector.

Parameters

selector (type or callable or None) – The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.

Returns

viewables

Return type

list(Viewable)

servable(title=None)

Serves the object if in a panel serve context and returns the Panel object to allow it to display itself in a notebook context.

Parameters

title (str) – A string title to give the Document (if served as an app)

Returns

Return type

The Panel object itself

server_doc(doc=None, title=None)

Returns a serveable bokeh Document with the panel attached

Parameters
  • doc (bokeh.Document (optional)) – The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()

  • title (str) – A string title to give the Document

Returns

doc – The bokeh document the panel was attached to

Return type

bokeh.Document

show(title=None, port=0, websocket_origin=None, threaded=False, verbose=True, open=True, **kwargs)

Starts a Bokeh server and displays the Viewable in a new tab.

Parameters
  • port (int (optional, default=0)) – Allows specifying a specific port

  • 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.

  • threaded (boolean (optional, default=False)) – Whether to launch the Server on a separate thread, allowing interactive use.

  • title (str) – A string title to give the Document (if served as an app)

  • verbose (boolean (optional, default=True)) – Whether to print the address and port

  • open (boolean (optional, default=True)) – Whether to open the server in a new browser tab

Returns

server – Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)

Return type

bokeh.server.Server or threading.Thread

class panel.viewable.Viewable(**params)[source]

Bases: panel.viewable.Layoutable, panel.viewable.ServableMixin

Viewable is the baseclass all objects in the panel library are built on. It defines the interface for declaring any object that displays itself by transforming the object(s) being wrapped into models that can be served using bokeh’s layout engine. The class also defines various methods that allow Viewable objects to be displayed in the notebook and on bokeh server.

Parameters inherited from:

panel.viewable.Layoutable: align, aspect_ratio, background, css_classes, width, height, min_width, min_height, max_width, max_height, margin, width_policy, height_policy, sizing_mode

app(notebook_url='localhost:8888', port=0)[source]

Displays a bokeh server app inline in the notebook.

Parameters
  • notebook_url (str) – URL to the notebook server

  • port (int (optional, default=0)) – Allows specifying a specific port

clone(**params)[source]

Makes a copy of the object sharing the same parameters.

Parameters

params (Keyword arguments override the parameters on the clone.) –

Returns

Return type

Cloned Viewable object

embed(max_states=1000, max_opts=3, json=False, save_path='./', load_path=None, progress=True)[source]

Renders a static version of a panel in a notebook by evaluating the set of states defined by the widgets in the model. Note this will only work well for simple apps with a relatively small state space.

Parameters
  • max_states (int) – The maximum number of states to embed

  • max_opts (int) – The maximum number of states for a single widget

  • json (boolean (default=True)) – Whether to export the data to json files

  • save_path (str (default='./')) – The path to save json files to

  • load_path (str (default=None)) – The path or URL the json files will be loaded from.

  • progress (boolean (default=False)) – Whether to report progress

get_root(doc=None, comm=None)[source]

Returns the root model and applies pre-processing hooks

Parameters
  • doc (bokeh.Document) – Bokeh document the bokeh model will be attached to.

  • comm (pyviz_comms.Comm) – Optional pyviz_comms when working in notebook

Returns

Return type

Returns the bokeh model corresponding to this panel object

pprint()[source]

Prints a compositional repr of the class.

save(filename, title=None, resources=None, template=None, template_variables=None, embed=False, max_states=1000, max_opts=3, embed_json=False, json_prefix='', save_path='./', load_path=None)[source]

Saves Panel objects to file.

Parameters
  • filename (string or file-like object) – Filename to save the plot to

  • title (string) – Optional title for the plot

  • resources (bokeh resources) – One of the valid bokeh.resources (e.g. CDN or INLINE)

  • template – passed to underlying io.save

  • template_variables – passed to underlying io.save

  • embed (bool) – Whether the state space should be embedded in the saved file.

  • max_states (int) – The maximum number of states to embed

  • max_opts (int) – The maximum number of states for a single widget

  • embed_json (boolean (default=True)) – Whether to export the data to json files

  • json_prefix (str (default='')) – Prefix for the auto-generated json directory

  • save_path (str (default='./')) – The path to save json files to

  • load_path (str (default=None)) – The path or URL the json files will be loaded from.

select(selector=None)[source]

Iterates over the Viewable and any potential children in the applying the Selector.

Parameters

selector (type or callable or None) – The selector allows selecting a subset of Viewables by declaring a type or callable function to filter by.

Returns

viewables

Return type

list(Viewable)

servable(title=None)

Serves the object if in a panel serve context and returns the Panel object to allow it to display itself in a notebook context.

Parameters

title (str) – A string title to give the Document (if served as an app)

Returns

Return type

The Panel object itself

server_doc(doc=None, title=None)[source]

Returns a serveable bokeh Document with the panel attached

Parameters
  • doc (bokeh.Document (optional)) – The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()

  • title (str) – A string title to give the Document

Returns

doc – The bokeh document the panel was attached to

Return type

bokeh.Document

show(title=None, port=0, websocket_origin=None, threaded=False, verbose=True, open=True, **kwargs)

Starts a Bokeh server and displays the Viewable in a new tab.

Parameters
  • port (int (optional, default=0)) – Allows specifying a specific port

  • 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.

  • threaded (boolean (optional, default=False)) – Whether to launch the Server on a separate thread, allowing interactive use.

  • title (str) – A string title to give the Document (if served as an app)

  • verbose (boolean (optional, default=True)) – Whether to print the address and port

  • open (boolean (optional, default=True)) – Whether to open the server in a new browser tab

Returns

server – Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)

Return type

bokeh.server.Server or threading.Thread