Skip to content

Commit da6b0ee

Browse files
MarcSkovMadsenMarc Skov MadsentchatonawaelchliFelonious-Spellfire
committed
Improves the PanelFrontend docs (#14493)
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)
1 parent 622d509 commit da6b0ee

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/lightning_app/frontend/panel/app_state_watcher.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
"""The AppStateWatcher enables a Frontend to.
1+
"""The ``AppStateWatcher`` enables a Frontend to:
22
33
- subscribe to App state changes
44
- to access and change the App state.
55
6-
This is particularly useful for the PanelFrontend but can be used by other Frontends too.
6+
This is particularly useful for the ``PanelFrontend`` but can be used by other frontends too.
77
"""
88
from __future__ import annotations
99

@@ -26,15 +26,16 @@
2626

2727

2828
class AppStateWatcher(Parameterized):
29-
"""The AppStateWatcher enables a Frontend to:
29+
"""The `AppStateWatcher` enables a Frontend to:
3030
3131
- Subscribe to any App state changes.
3232
- To access and change the App state from the UI.
3333
34-
This is particularly useful for the PanelFrontend, but can be used by
35-
other Frontend's too.
34+
This is particularly useful for the `PanelFrontend , but can be used by
35+
other frontends too.
3636
37-
Example:
37+
Example
38+
-------
3839
3940
.. code-block:: python
4041
@@ -54,10 +55,10 @@ def update(state):
5455
5556
This would print ``The counter was updated to 2``.
5657
57-
The AppStateWatcher is built on top of Param which is a framework like dataclass, attrs and
58+
The ``AppStateWatcher`` is built on top of Param, which is a framework like dataclass, attrs and
5859
Pydantic which additionally provides powerful and unique features for building reactive apps.
5960
60-
Please note the AppStateWatcher is a singleton, i.e. only one instance is instantiated
61+
Please note the ``AppStateWatcher`` is a singleton, i.e., only one instance is instantiated
6162
"""
6263

6364
state: AppState = ClassSelector(
@@ -75,7 +76,7 @@ def __new__(cls):
7576

7677
@requires("param")
7778
def __init__(self):
78-
# It's critical to initialize only once
79+
# It is critical to initialize only once
7980
# See https://github.com/holoviz/param/issues/643
8081
if not hasattr(self, "_initialized"):
8182
super().__init__(name="singleton")

src/lightning_app/frontend/panel/panel_frontend.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,36 @@ def _has_panel_autoreload() -> bool:
2727

2828

2929
class PanelFrontend(Frontend):
30-
"""The PanelFrontend enables you to serve Panel code as a Frontend for your LightningFlow.
30+
"""The `PanelFrontend` enables you to serve Panel code as a Frontend for your LightningFlow.
3131
32-
To use this frontend, you must first install the `panel` package:
32+
Reference: https://lightning.ai/lightning-docs/workflows/add_web_ui/panel/
33+
34+
Args:
35+
entry_point: The path to a .py or .ipynb file, or a pure function. The file or function must contain your Panel
36+
code. The function can optionally accept an ``AppStateWatcher`` argument.
37+
38+
Raises:
39+
TypeError: Raised if the ``entry_point`` provided is a class method
40+
41+
Example:
42+
43+
To use the `PanelFrontend`, you must first install the `panel` package:
3344
3445
.. code-block:: bash
3546
3647
pip install panel
3748
38-
Example:
49+
Create the files `panel_app_basic.py` and `app_basic.py` with the content below.
3950
40-
`panel_app_basic.py`
51+
**panel_app_basic.py**
4152
4253
.. code-block:: python
4354
4455
import panel as pn
4556
4657
pn.panel("Hello **Panel ⚡** World").servable()
4758
48-
`app_basic.py`
59+
**app_basic.py**
4960
5061
.. code-block:: python
5162
@@ -69,20 +80,15 @@ def configure_layout(self):
6980
7081
app = L.LightningApp(LitApp())
7182
72-
You can start the Lightning server with Panel autoreload by setting the `PANEL_AUTORELOAD`
73-
environment variable to 'yes': `PANEL_AUTORELOAD=yes lightning run app app_basic.py`.
83+
Start the Lightning server with `lightning run app app_basic.py`.
7484
75-
Args:
76-
entry_point: A pure function or the path to a .py or .ipynb file.
77-
The function must be a pure function that contains your Panel code.
78-
The function can optionally accept an `AppStateWatcher` argument.
79-
80-
Raises:
81-
TypeError: Raised if the entry_point is a class method
85+
For development you can get Panel autoreload by setting the ``PANEL_AUTORELOAD``
86+
environment variable to 'yes', i.e. run
87+
``PANEL_AUTORELOAD=yes lightning run app app_basic.py``
8288
"""
8389

8490
@requires("panel")
85-
def __init__(self, entry_point: Callable | str):
91+
def __init__(self, entry_point: str | Callable):
8692
super().__init__()
8793

8894
if inspect.ismethod(entry_point):

0 commit comments

Comments
 (0)