panel.io.pages module#

Theming of the pages Panel serves outside of applications, i.e. the index, login, logout and error pages.

The pages are configured with config.page_config, which mirrors the theming parameters of panel.ui.Page so that the same theme_config, logo and title can be shared between the server pages and the applications.

class panel.io.pages.PageTheme[source]#

Bases: object

Exposes config.page_config to the page templates as page. It is resolved on every access, so changes to the config apply without a restart and no stale state is captured at import time.

Attributes:
config
css
dark_theme
favicon
head

The stylesheets of the page, to be inserted unescaped into <head>.

logo
site_url
title

Methods

brand(title[, tag, href])

Renders the logo and title of the app bar, to be inserted unescaped.

brand(title: str, tag: str = 'span', href: str | None = None) → str[source]#

Renders the logo and title of the app bar, to be inserted unescaped.

property head: str#

The stylesheets of the page, to be inserted unescaped into <head>.

panel.io.pages.contrast_text(color: str) → str[source]#

The text color MUI’s getContrastText picks for the given background. Colors that cannot be parsed are assumed to be dark.

panel.io.pages.load_page_config(value: Any) → dict[str, Any][source]#

Normalize a page configuration given as a dict, a JSON string or a path to a JSON file, and validate its keys.

panel.io.pages.page_defaults() → dict[str, Any][source]#

The branding configured as class defaults of panel.ui.Page, e.g. by a --setup script, so that applications and server pages share one brand configuration. Only consulted once panel-material-ui is imported, since importing it replaces the global design.

panel.io.pages.resolve_image(image: str | PathLike | None) → str | None[source]#

Embeds local image files as data URIs so the pages do not depend on static routes, and passes URLs through unchanged.

panel.io.pages.theme_css(theme_config: dict | None, dark_theme: bool | None = None) → str[source]#

Translates a MUI theme_config into overrides of the page stylesheet variables. With dark_theme=None the pages follow the color scheme of the operating system, otherwise the given scheme is forced.