viewable Module#
viewable
Module#
Defines the baseclasses that make a component render to a bokeh model and become viewable including:
Layoutable: Defines parameters concerned with layout and style
ServableMixin: Mixin class that defines methods to serve object on server
Renderable: Defines methods to render a component as a bokeh model
Viewable: Defines methods to view the component in the notebook, on the server or in static exports
- class panel.viewable.Layoutable(*, align, aspect_ratio, css_classes, design, height, height_policy, margin, max_height, max_width, min_height, min_width, sizing_mode, styles, stylesheets, tags, visible, width, width_policy, name)[source]#
Bases:
Parameterized
Layoutable defines shared style and layout related parameters for all Panel components with a visual representation.
align
= param.Align(allow_refs=True, default=âstartâ, label=âAlignâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bb27a10>)Whether the object should be aligned with the start, end or center of its container. If set as a tuple it will declare (vertical, horizontal) alignment.
aspect_ratio
= param.Aspect(allow_None=True, allow_refs=True, label=âAspect ratioâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bb0a390>)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).css_classes
= param.List(allow_refs=True, bounds=(0, None), default=[], label=âCss classesâ, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x16bde4bd0>)CSS classes to apply to the layout.
design
= param.ObjectSelector(allow_refs=True, label=âDesignâ, names={}, nested_refs=False, objects=[None], rx=<param.reactive.reactive_ops object at 0x16bb27950>)The design system to use to style components.
height
= param.Integer(allow_None=True, allow_refs=True, bounds=(0, None), inclusive_bounds=(True, True), label=âHeightâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bb09bd0>)The height of the component (in pixels). This can be either fixed or preferred height, depending on height sizing policy.
min_width
= param.Integer(allow_None=True, allow_refs=True, bounds=(0, None), inclusive_bounds=(True, True), label=âMin widthâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bb0a350>)Minimal width of the component (in pixels) if width is adjustable.
min_height
= param.Integer(allow_None=True, allow_refs=True, bounds=(0, None), inclusive_bounds=(True, True), label=âMin heightâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bb0a290>)Minimal height of the component (in pixels) if height is adjustable.
max_width
= param.Integer(allow_None=True, allow_refs=True, bounds=(0, None), inclusive_bounds=(True, True), label=âMax widthâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bb09b90>)Minimal width of the component (in pixels) if width is adjustable.
max_height
= param.Integer(allow_None=True, allow_refs=True, bounds=(0, None), inclusive_bounds=(True, True), label=âMax heightâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bb0a450>)Minimal height of the component (in pixels) if height is adjustable.
margin
= param.Margin(allow_None=True, allow_refs=True, default=0, label=âMarginâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16ba01cd0>)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).
styles
= param.Dict(allow_refs=True, class_=<class âdictâ>, default={}, label=âStylesâ, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x16ba31f90>)Dictionary of CSS rules to apply to DOM node wrapping the component.
stylesheets
= param.List(allow_refs=True, bounds=(0, None), default=[], label=âStylesheetsâ, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x16bbb1110>)List of stylesheets defined as URLs pointing to .css files or raw CSS defined as a string.
tags
= param.List(allow_refs=True, bounds=(0, None), default=[], label=âTagsâ, nested_refs=True, rx=<param.reactive.reactive_ops object at 0x16ba31f90>)List of arbitrary tags to add to the component. Can be useful for templating or for storing metadata on the model.
width
= param.Integer(allow_None=True, allow_refs=True, bounds=(0, None), inclusive_bounds=(True, True), label=âWidthâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bde8c90>)The width of the component (in pixels). This can be either fixed or preferred width, depending on width sizing policy.
width_policy
= param.ObjectSelector(allow_refs=True, default=âautoâ, label=âWidth policyâ, names={}, nested_refs=False, objects=[âautoâ, âfixedâ, âfitâ, âminâ, âmaxâ], rx=<param.reactive.reactive_ops object at 0x16ba1d410>)Describes how the component should maintain its width.
"auto"
Use componentâs preferred sizing policy."fixed"
Use exactlywidth
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(allow_refs=True, default=âautoâ, label=âHeight policyâ, names={}, nested_refs=False, objects=[âautoâ, âfixedâ, âfitâ, âminâ, âmaxâ], rx=<param.reactive.reactive_ops object at 0x16ba1cd50>)Describes how the component should maintain its height.
"auto"
Use componentâs preferred sizing policy."fixed"
Use exactlyheight
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(allow_refs=True, label=âSizing modeâ, names={}, nested_refs=False, objects=[âfixedâ, âstretch_widthâ, âstretch_heightâ, âstretch_bothâ, âscale_widthâ, âscale_heightâ, âscale_bothâ, None], rx=<param.reactive.reactive_ops object at 0x16bb42850>)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
andaspect_ratio
instead (those take precedence oversizing_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.visible
= param.Boolean(allow_refs=True, default=True, label=âVisibleâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16ba64190>)Whether the component is visible. Setting visible to false will hide the component entirely.
- class panel.viewable.Viewable(*, loading, align, aspect_ratio, css_classes, design, height, height_policy, margin, max_height, max_width, min_height, min_width, sizing_mode, styles, stylesheets, tags, visible, width, width_policy, name)[source]#
Bases:
Renderable
,Layoutable
,ServableMixin
Viewable is the baseclass all visual components 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, css_classes, design, height, min_width, min_height, max_width, max_height, margin, styles, stylesheets, tags, width, width_policy, height_policy, sizing_mode, visibleloading
= param.Boolean(allow_refs=True, default=False, label=âLoadingâ, nested_refs=False, rx=<param.reactive.reactive_ops object at 0x16bb0ac90>)Whether or not the Viewable is loading. If True a loading spinner is shown on top of the Viewable.
- clone(**params) Viewable [source]#
Makes a copy of the object sharing the same parameters.
Arguments#
params: Keyword arguments override the parameters on the clone.
Returns#
Cloned Viewable object
- embed(max_states: int = 1000, max_opts: int = 3, json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = False, states={}) None [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.
Arguments#
- 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
- json_prefix: str (default=ââ)
Prefix for JSON filename
- 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
- states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- get_root(doc: Document | None = None, comm: Comm | None = None, preprocess: bool = True) Model [source]#
Returns the root model and applies pre-processing hooks
Arguments#
- doc: bokeh.Document
Bokeh document the bokeh model will be attached to.
- comm: pyviz_comms.Comm
Optional pyviz_comms when working in notebook
- preprocess: boolean (default=True)
Whether to run preprocessing hooks
Returns#
Returns the bokeh model corresponding to this panel object
- save(filename: str | PathLike | IO, title: str | None = None, resources: Resources | None = None, template: str | Template | None = None, template_variables: dict[str, Any] = {}, embed: bool = False, max_states: int = 1000, max_opts: int = 3, embed_json: bool = False, json_prefix: str = '', save_path: str = './', load_path: str | None = None, progress: bool = True, embed_states: dict[Any, Any] = {}, as_png: bool | None = None, **kwargs) None [source]#
Saves Panel objects to file.
Arguments#
- filename: str 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.
- progress: boolean (default=True)
Whether to report progress
- embed_states: dict (default={})
A dictionary specifying the widget values to embed for each widget
- as_png: boolean (default=None)
To save as a .png. If None save_png will be true if filename is string and ends with png.
- select(selector: type | Callable[[Viewable], bool] | None = None) list[Viewable] [source]#
Iterates over the Viewable and any potential children in the applying the Selector.
Arguments#
- 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: list(Viewable)
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) ServableMixin [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- server_doc(doc: Document | None = None, title: str | None = None, location: bool | 'Location' = True) Document [source]#
Returns a serveable bokeh Document with the panel attached
Arguments#
- docbokeh.Document (optional)
The bokeh Document to attach the panel to as a root, defaults to bokeh.io.curdoc()
- titlestr
A string title to give the Document
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- docbokeh.Document
The bokeh document the panel was attached to
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) StoppableThread' | 'Server [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- 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.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)
- class panel.viewable.Viewer(*, name)[source]#
Bases:
Parameterized
A baseclass for custom components that behave like a Panel object. By implementing __panel__ method an instance of this class will behave like the returned Panel component when placed in a layout, render itself in a notebook and provide show and servable methods.
- servable(title: str | None = None, location: bool | 'Location' = True, area: str = 'main', target: str | None = None) Viewable [source]#
Serves the object or adds it to the configured pn.state.template if in a panel serve context, writes to the DOM if in a pyodide context and returns the Panel object to allow it to display itself in a notebook context.
Arguments#
- titlestr
A string title to give the Document (if served as an app)
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
- area: str (deprecated)
The area of a template to add the component too. Only has an effect if pn.config.template has been set.
- target: str
Target area to write to. If a template has been configured on pn.config.template this refers to the target area in the template while in pyodide this refers to the ID of the DOM node to write to.
Returns#
The Panel object itself
- show(title: str | None = None, port: int = 0, address: str | None = None, websocket_origin: str | None = None, threaded: bool = False, verbose: bool = True, open: bool = True, location: bool | 'Location' = True, **kwargs) threading.Thread | 'Server' [source]#
Starts a Bokeh server and displays the Viewable in a new tab.
Arguments#
- titlestr | None
A string title to give the Document (if served as an app)
- 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.
- threaded: boolean (optional, default=False)
Whether to launch the Server on a separate thread, allowing interactive use.
- verbose: boolean (optional, default=True)
Whether to print the address and port
- openboolean (optional, default=True)
Whether to open the server in a new browser tab
- locationboolean or panel.io.location.Location
Whether to create a Location component to observe and set the URL location.
Returns#
- server: bokeh.server.Server or panel.io.server.StoppableThread
Returns the Bokeh server instance or the thread the server was launched on (if threaded=True)