Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves the PanelFrontend docs #14493

Merged
merged 139 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from 129 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
2d30511
wip app pull state
Jul 4, 2022
50f1e2a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 4, 2022
3a22d2f
basic principle
Jul 7, 2022
d65cb88
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
Jul 7, 2022
2bf02c5
Merge branch 'master' of https://github.com/Lightning-AI/lightning in…
Jul 8, 2022
cd133c6
general principle working
Jul 8, 2022
b4dc86d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 8, 2022
8e50ca1
refactor
MarcSkovMadsen Jul 9, 2022
77bc568
Merge branch 'master' of https://github.com/Lightning-AI/lightning in…
Jul 9, 2022
6ab3644
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
MarcSkovMadsen Jul 9, 2022
cbff6ec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 9, 2022
78a152e
add panel as a requirement
MarcSkovMadsen Jul 9, 2022
017be8e
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
Jul 9, 2022
8974b1d
fix flake errors
MarcSkovMadsen Jul 9, 2022
e4e8593
work around that I cannot run lightning app when developing
MarcSkovMadsen Jul 9, 2022
8e5b62c
fix singleton issues
MarcSkovMadsen Jul 9, 2022
9ca5085
fix test issues
MarcSkovMadsen Jul 10, 2022
9295e09
refactor and add support for serving files
Jul 10, 2022
7cbf446
refactor and improve
Jul 10, 2022
2d11c23
add more support for autoreload
Jul 11, 2022
7f94c4a
Make autoreload work great for panel .py and .ipynb files
Jul 11, 2022
7f38248
panel serve render_fn too
Jul 11, 2022
1722e4f
dont use log files when running locally
Jul 12, 2022
0158f36
refactor github model runner
Jul 12, 2022
75e482a
fix issue
Jul 13, 2022
2ae8e87
add basic docs
Jul 13, 2022
4fd2cf1
fix errors
Jul 13, 2022
2190b63
add panel intro
Jul 13, 2022
ed3fbeb
add more gifs
Jul 13, 2022
fc5e2c5
fix link
Jul 13, 2022
7b28e9d
git push
Jul 13, 2022
30110e4
simplify
Jul 13, 2022
7329a49
add more docs
Jul 13, 2022
b75bdad
change app_basic to app
Jul 13, 2022
8576e12
add panel to documentation
Jul 13, 2022
a2700bc
update docs
Jul 13, 2022
2fad50d
change counter to count
Jul 13, 2022
c424f21
add github runner visuals
Jul 13, 2022
f2f0910
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2022
b4cc495
clean up PR
Jul 29, 2022
4afc7c5
change video links
Jul 29, 2022
dd19fc2
update links
Jul 29, 2022
9420a0c
fix link
Jul 29, 2022
9c210ee
minor improvements
Jul 29, 2022
1d0427d
fix small issues
Jul 29, 2022
21c5e1a
fix minor spelling errors
Jul 29, 2022
e907620
update
tchaton Aug 1, 2022
825d34d
update
tchaton Aug 1, 2022
b93824c
update
tchaton Aug 11, 2022
f88027e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2022
1ce3869
Merge branch 'master' into pr-13531
tchaton Aug 11, 2022
72b27e6
update
tchaton Aug 11, 2022
b6a1e75
Merge branch 'pr-13531' of https://github.com/Lightning-AI/lightning …
tchaton Aug 11, 2022
1ed7a0b
Merge branch 'master' into feature/panel-frontend-intermediate
tchaton Aug 11, 2022
6c39414
remove bad merge
tchaton Aug 11, 2022
218b385
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
tchaton Aug 11, 2022
d9cd9b9
Merge branch 'master' into feature/panel-frontend-intermediate
tchaton Aug 12, 2022
dd1a28d
update
tchaton Aug 12, 2022
da701e4
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
tchaton Aug 12, 2022
67f2e10
Update src/lightning_app/frontend/utilities/app_state_watcher.py
MarcSkovMadsen Aug 13, 2022
1b05d11
simplify server_entry_point to entry_point
MarcSkovMadsen Aug 13, 2022
9022b19
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 13, 2022
94cc189
remove duplicate code
MarcSkovMadsen Aug 13, 2022
0cab517
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
MarcSkovMadsen Aug 13, 2022
2898095
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 13, 2022
41ee139
move has_panel_auto_reload
MarcSkovMadsen Aug 13, 2022
ba49306
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
MarcSkovMadsen Aug 13, 2022
866ac06
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 13, 2022
7334a16
fix imports
MarcSkovMadsen Aug 13, 2022
554fe41
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
MarcSkovMadsen Aug 13, 2022
f77edf1
Update src/lightning_app/CHANGELOG.md
Felonious-Spellfire Aug 13, 2022
c622562
Update src/lightning_app/frontend/panel/__init__.py
Felonious-Spellfire Aug 13, 2022
ec43faf
Update src/lightning_app/frontend/panel/panel_frontend.py
Felonious-Spellfire Aug 13, 2022
cc91fde
Update src/lightning_app/frontend/utilities/app_state_comm.py
Felonious-Spellfire Aug 13, 2022
479f9d4
Update tests/tests_app/frontend/utilities/test_utils.py
Felonious-Spellfire Aug 13, 2022
c2a1ff5
Update tests/tests_app/frontend/utilities/test_utils.py
Felonious-Spellfire Aug 13, 2022
4685e01
Update tests/tests_app/frontend/utilities/test_app_state_watcher.py
Felonious-Spellfire Aug 13, 2022
f4e6f0b
Update tests/tests_app/frontend/utilities/test_app_state_watcher.py
Felonious-Spellfire Aug 13, 2022
5253343
Update tests/tests_app/frontend/panel/test_panel_serve_render_fn.py
Felonious-Spellfire Aug 13, 2022
ebe849b
Update tests/tests_app/frontend/utilities/test_app_state_comm.py
Felonious-Spellfire Aug 13, 2022
02d66a4
Update tests/tests_app/frontend/utilities/test_app_state_comm.py
Felonious-Spellfire Aug 13, 2022
fc790b3
Update tests/tests_app/frontend/panel/test_panel_frontend.py
Felonious-Spellfire Aug 13, 2022
14f3e1a
Update src/lightning_app/frontend/utilities/app_state_watcher.py
Felonious-Spellfire Aug 13, 2022
bc0cab8
Update src/lightning_app/frontend/utilities/app_state_watcher.py
Felonious-Spellfire Aug 13, 2022
f2331ba
Update src/lightning_app/frontend/utilities/app_state_comm.py
Felonious-Spellfire Aug 13, 2022
303d7cd
Update src/lightning_app/frontend/utilities/app_state_watcher.py
Felonious-Spellfire Aug 13, 2022
e83f328
Update src/lightning_app/frontend/utilities/app_state_watcher.py
Felonious-Spellfire Aug 13, 2022
2ead2a1
Update src/lightning_app/frontend/utilities/utils.py
Felonious-Spellfire Aug 13, 2022
3c13fb3
Update src/lightning_app/frontend/utilities/utils.py
Felonious-Spellfire Aug 13, 2022
d8a4230
Update src/lightning_app/utilities/state.py
Felonious-Spellfire Aug 13, 2022
1b97964
Update tests/tests_app/frontend/utilities/test_app_state_comm.py
Felonious-Spellfire Aug 13, 2022
aeeca10
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 13, 2022
9e33ad8
Update src/lightning_app/frontend/panel/panel_serve_render_fn.py
Felonious-Spellfire Aug 13, 2022
c918d8a
Update src/lightning_app/frontend/utilities/app_state_comm.py
Felonious-Spellfire Aug 13, 2022
2cad363
remove unused imports
MarcSkovMadsen Aug 14, 2022
8541d76
Merge branch 'feature/panel-frontend-intermediate' of https://github.…
MarcSkovMadsen Aug 14, 2022
8718028
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 14, 2022
35463ec
revert code-owner change
awaelchli Aug 15, 2022
ed29d8f
move images to s3
awaelchli Aug 15, 2022
5e12765
move is_running_locally utility function
awaelchli Aug 15, 2022
0df0fb5
move get_allowed_hosts
awaelchli Aug 15, 2022
3e0a606
organize utilities
awaelchli Aug 15, 2022
246eb74
organize tests
awaelchli Aug 15, 2022
865fb25
formatting
awaelchli Aug 15, 2022
826f406
Merge branch 'master' into feature/panel-frontend-intermediate
awaelchli Aug 15, 2022
d25287d
Review of content
Felonious-Spellfire Aug 13, 2022
c6a25f0
Merge branch 'master' into feature/panel-frontend-intermediate
awaelchli Aug 15, 2022
ccaf613
reset cli changes
awaelchli Aug 15, 2022
452756b
Merge branch 'master' into feature/panel-frontend-intermediate
Borda Aug 17, 2022
f4dc620
Merge branch 'master' into feature/panel-frontend-intermediate
manskx Aug 18, 2022
8476137
Merge branch 'master' into feature/panel-frontend-intermediate
Borda Aug 23, 2022
29822b2
docs
Borda Aug 23, 2022
cf27a29
update docstring
MarcSkovMadsen Sep 2, 2022
100d231
Merge branch 'master' of https://github.com/Lightning-AI/lightning in…
MarcSkovMadsen Sep 2, 2022
1501835
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 2, 2022
2a6e9c1
revert merge issues
MarcSkovMadsen Sep 2, 2022
b00a059
Merge branch 'fix/docs' of https://github.com/MarcSkovMadsen/lightnin…
MarcSkovMadsen Sep 2, 2022
346c00a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 2, 2022
6d81e18
fix merge issues
MarcSkovMadsen Sep 2, 2022
0ec1d90
Merge branch 'fix/docs' of https://github.com/MarcSkovMadsen/lightnin…
MarcSkovMadsen Sep 2, 2022
4fd7733
remove spacing
MarcSkovMadsen Sep 2, 2022
d7866c3
small docs improvements
MarcSkovMadsen Sep 2, 2022
82b49c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 2, 2022
4ab2546
Merge branch 'master' into fix/docs
tchaton Sep 4, 2022
392f41f
Apply suggestions from code review
Borda Sep 22, 2022
d11df1a
Apply suggestions from code review
Borda Sep 22, 2022
bcc1beb
Union
Borda Sep 22, 2022
e855904
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2022
183d4c8
Merge branch 'master' into fix/docs
tchaton Sep 28, 2022
4c0d12a
Merge branch 'master' into fix/docs
awaelchli Oct 4, 2022
eea8594
precommit fixes
awaelchli Oct 4, 2022
51ec603
Merge branch 'master' into fix/docs
awaelchli Oct 5, 2022
560fdf3
Merge branch 'master' into fix/docs
Borda Oct 5, 2022
c905f5e
Merge branch 'master' into fix/docs
awaelchli Oct 5, 2022
d281d35
Merge branch 'master' into fix/docs
Borda Oct 10, 2022
92c3774
Merge branch 'master' into fix/docs
Borda Oct 25, 2022
efa26a0
Merge branch 'master' into fix/docs
Borda Nov 8, 2022
fbf52c6
Merge branch 'master' into fix/docs
justusschock Nov 9, 2022
a680d15
Merge branch 'master' into fix/docs
carmocca Nov 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 22 additions & 16 deletions src/lightning_app/frontend/panel/panel_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pathlib
import subprocess
import sys
from typing import Callable, TextIO
from typing import Callable, TextIO, Union

from lightning_app.frontend.frontend import Frontend
from lightning_app.frontend.utils import _get_frontend_environment
Expand All @@ -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': `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):
Borda marked this conversation as resolved.
Show resolved Hide resolved
super().__init__()

if inspect.ismethod(entry_point):
Expand Down