Skip to content

Commit

Permalink
Improves the PanelFrontend docs (#14493)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Skov Madsen <[email protected]>
Co-authored-by: thomas chaton <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
Co-authored-by: Felonious-Spellfire <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Mansy <[email protected]>
(cherry picked from commit 10a4b24)
  • Loading branch information
MarcSkovMadsen authored and Borda committed Nov 16, 2022
1 parent 622d509 commit da6b0ee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
19 changes: 10 additions & 9 deletions src/lightning_app/frontend/panel/app_state_watcher.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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")
Expand Down
36 changes: 21 additions & 15 deletions src/lightning_app/frontend/panel/panel_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,36 @@ 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
import panel as pn
pn.panel("Hello **Panel ⚡** World").servable()
`app_basic.py`
**app_basic.py**
.. code-block:: python
Expand All @@ -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):
Expand Down

0 comments on commit da6b0ee

Please sign in to comment.