phenotypic.tools_.panel_ module#

Shared Panel toolkit for interactive dashboards.

Centralises Panel availability checks, Jupyter environment detection, and pn.extension() initialization so that every module using Panel imports from one place instead of reimplementing these patterns.

phenotypic.tools_.panel_.display_or_return(layout, *, show: bool = True)[source]#

Display a Panel layout in Jupyter or return it for programmatic use.

When show is True and the session is a Jupyter notebook the layout is passed to IPython.display.display (after ensuring the Panel extension is loaded). Otherwise the layout is returned as-is.

Parameters:
  • layout – A Panel layout object (e.g. pn.Column).

  • show (bool) – If True, attempt to display interactively.

Returns:

The layout object (always returned, even after display).

phenotypic.tools_.panel_.ensure_panel_extension(*extensions: str, **kwargs) None[source]#

Initialise pn.extension() once, only when inside IPython.

Safe to call multiple times — the extension is loaded at most once per process. Outside IPython the call is a silent no-op. When plotly is importable it is automatically included as an extension so Plotly figures render correctly in Panel layouts. The comms kwarg is auto-detected via _detect_comms() unless the caller supplies one explicitly.

Parameters:
  • *extensions (str) – Extra Panel extensions to load (e.g. "tabulator"). "plotly" is added automatically when Plotly is installed.

  • **kwargs – Forwarded to pn.extension() on the first call (e.g. inline=True). An explicit comms value wins over the auto-detected default.

Return type:

None

phenotypic.tools_.panel_.in_ipython() bool[source]#

Detect whether code is running inside any IPython session.

Returns:

True when an IPython kernel or terminal is active.

Return type:

bool

phenotypic.tools_.panel_.in_jupyter() bool[source]#

Detect whether code is running inside a Jupyter notebook.

This is stricter than in_ipython() — it returns True only for notebook kernels (ZMQInteractiveShell), not plain IPython terminals.

Returns:

True when running in a Jupyter notebook kernel.

Return type:

bool

phenotypic.tools_.panel_.require_panel() None[source]#

Raise ImportError with an actionable message if Panel is missing.

Raises:

ImportError – If panel is not installed.

Return type:

None

phenotypic.tools_.panel_.PANEL_AVAILABLE: bool = True#

True when the panel package is importable.

phenotypic.tools_.panel_.PANEL_IMPORT_ERROR: str = "Panel is required for interactive dashboards. Install it with: pip install 'phenotypic[gui]'"#

User-facing error message when Panel is missing.

phenotypic.tools_.panel_.PLOTLY_AVAILABLE: bool = True#

True when the plotly package is importable.