diff --git a/src/lightning_app/frontend/panel/app_state_watcher.py b/src/lightning_app/frontend/panel/app_state_watcher.py index 2c886bae341f5..2253312a13565 100644 --- a/src/lightning_app/frontend/panel/app_state_watcher.py +++ b/src/lightning_app/frontend/panel/app_state_watcher.py @@ -1,9 +1,9 @@ -"""The AppStateWatcher enables a Frontend to. +"""The ``AppStateWatcher`` enables a Frontend to: - subscribe to App state changes - to access and change the App state. -This is particularly useful for the PanelFrontend but can be used by other Frontends too. +This is particularly useful for the ``PanelFrontend`` but can be used by other frontends too. """ from __future__ import annotations @@ -26,15 +26,16 @@ class AppStateWatcher(Parameterized): - """The AppStateWatcher enables a Frontend to: + """The `AppStateWatcher` enables a Frontend to: - Subscribe to any App state changes. - To access and change the App state from the UI. - This is particularly useful for the PanelFrontend, but can be used by - other Frontend's too. + This is particularly useful for the `PanelFrontend , but can be used by + other frontends too. - Example: + Example + ------- .. code-block:: python @@ -54,10 +55,10 @@ def update(state): This would print ``The counter was updated to 2``. - The AppStateWatcher is built on top of Param which is a framework like dataclass, attrs and + The ``AppStateWatcher`` is built on top of Param, which is a framework like dataclass, attrs and Pydantic which additionally provides powerful and unique features for building reactive apps. - Please note the AppStateWatcher is a singleton, i.e. only one instance is instantiated + Please note the ``AppStateWatcher`` is a singleton, i.e., only one instance is instantiated """ state: AppState = ClassSelector( @@ -75,7 +76,7 @@ def __new__(cls): @requires("param") def __init__(self): - # It's critical to initialize only once + # It is critical to initialize only once # See https://github.com/holoviz/param/issues/643 if not hasattr(self, "_initialized"): super().__init__(name="singleton") diff --git a/src/lightning_app/frontend/panel/panel_frontend.py b/src/lightning_app/frontend/panel/panel_frontend.py index 359dca28b2766..48af9235fa796 100644 --- a/src/lightning_app/frontend/panel/panel_frontend.py +++ b/src/lightning_app/frontend/panel/panel_frontend.py @@ -27,17 +27,28 @@ def _has_panel_autoreload() -> bool: class PanelFrontend(Frontend): - """The PanelFrontend enables you to serve Panel code as a Frontend for your LightningFlow. + """The `PanelFrontend` enables you to serve Panel code as a Frontend for your LightningFlow. - To use this frontend, you must first install the `panel` package: + Reference: https://lightning.ai/lightning-docs/workflows/add_web_ui/panel/ + + Args: + entry_point: The path to a .py or .ipynb file, or a pure function. The file or function must contain your Panel + code. The function can optionally accept an ``AppStateWatcher`` argument. + + Raises: + TypeError: Raised if the ``entry_point`` provided is a class method + + Example: + + To use the `PanelFrontend`, you must first install the `panel` package: .. code-block:: bash pip install panel - Example: + Create the files `panel_app_basic.py` and `app_basic.py` with the content below. - `panel_app_basic.py` + **panel_app_basic.py** .. code-block:: python @@ -45,7 +56,7 @@ class PanelFrontend(Frontend): pn.panel("Hello **Panel ⚡** World").servable() - `app_basic.py` + **app_basic.py** .. code-block:: python @@ -69,20 +80,15 @@ def configure_layout(self): app = L.LightningApp(LitApp()) - You can start the Lightning server with Panel autoreload by setting the `PANEL_AUTORELOAD` - environment variable to 'yes': `PANEL_AUTORELOAD=yes lightning run app app_basic.py`. + Start the Lightning server with `lightning run app app_basic.py`. - Args: - entry_point: A pure function or the path to a .py or .ipynb file. - The function must be a pure function that contains your Panel code. - The function can optionally accept an `AppStateWatcher` argument. - - Raises: - TypeError: Raised if the entry_point is a class method + For development you can get Panel autoreload by setting the ``PANEL_AUTORELOAD`` + environment variable to 'yes', i.e. run + ``PANEL_AUTORELOAD=yes lightning run app app_basic.py`` """ @requires("panel") - def __init__(self, entry_point: Callable | str): + def __init__(self, entry_point: str | Callable): super().__init__() if inspect.ismethod(entry_point):