Skip to content

Commit d2840a2

Browse files
awaelchlirohitgr7
andauthored
Update examples that require the run() method (#15096)
Co-authored-by: Rohit Gupta <[email protected]>
1 parent b4b651c commit d2840a2

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

docs/source-app/workflows/add_web_ui/html/basic.rst

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,27 @@ First **create a file named app.py** with the app content (in the same folder as
5353
5454
# app.py
5555
import lightning as L
56+
import lightning.app.frontend as frontend
57+
5658
5759
class HelloComponent(L.LightningFlow):
5860
def configure_layout(self):
59-
return L.app.frontend.web.StaticWebFrontend(serve_dir='.')
61+
return frontend.StaticWebFrontend(serve_dir='.')
62+
6063
6164
class LitApp(L.LightningFlow):
6265
def __init__(self):
6366
super().__init__()
6467
self.hello_component = HelloComponent()
6568
69+
def run(self):
70+
self.hello_component.run()
71+
6672
def configure_layout(self):
6773
tab1 = {"name": "home", "content": self.hello_component}
6874
return tab1
6975
76+
7077
app = L.LightningApp(LitApp())
7178
7279
----
@@ -100,20 +107,24 @@ Enable an HTML UI for the component
100107
Give the component an HTML UI, by returning a ``StaticWebFrontend`` object from the ``configure_layout`` method:
101108

102109
.. code:: bash
103-
:emphasize-lines: 5,6
110+
:emphasize-lines: 6,7
104111
105112
# app.py
106113
import lightning as L
114+
import lightning.app.frontend as frontend
107115
108116
class HelloComponent(L.LightningFlow):
109117
def configure_layout(self):
110-
return L.app.frontend.web.StaticWebFrontend(serve_dir='.')
118+
return frontend.StaticWebFrontend(serve_dir='.')
111119
112120
class LitApp(L.LightningFlow):
113121
def __init__(self):
114122
super().__init__()
115123
self.hello_component = HelloComponent()
116124
125+
def run(self):
126+
self.hello_component.run()
127+
117128
def configure_layout(self):
118129
tab1 = {"name": "home", "content": self.hello_component}
119130
return tab1
@@ -129,21 +140,25 @@ Route the UI in the root component
129140
The final step, is to tell the Root component in which tab to render this component's UI.
130141
In this case, we render the ``HelloComponent`` UI in the ``home`` tab of the application.
131142

132-
.. code:: bash
133-
:emphasize-lines: 14, 15
143+
.. code:: python
144+
:emphasize-lines: 18, 19
134145
135146
# app.py
136147
import lightning as L
148+
import lightning.app.frontend as frontend
137149
138150
class HelloComponent(L.LightningFlow):
139151
def configure_layout(self):
140-
return L.app.frontend.web.StaticWebFrontend(serve_dir='.')
152+
return frontend.StaticWebFrontend(serve_dir='.')
141153
142154
class LitApp(L.LightningFlow):
143155
def __init__(self):
144156
super().__init__()
145157
self.hello_component = HelloComponent()
146158
159+
def run(self):
160+
self.hello_component.run()
161+
147162
def configure_layout(self):
148163
tab1 = {"name": "home", "content": self.hello_component}
149164
return tab1

docs/source-app/workflows/add_web_ui/panel/basic.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ Then, create a file named ``app.py`` with the following App content:
8484
super().__init__()
8585
self.lit_panel = LitPanel()
8686
87+
def run(self):
88+
self.lit_panel.run()
89+
8790
def configure_layout(self):
8891
return {"name": "home", "content": self.lit_panel}
8992
@@ -172,6 +175,9 @@ the ``configure_layout`` method of the Lightning Component you want to connect t
172175
super().__init__()
173176
self.lit_panel = LitPanel()
174177
178+
def run(self):
179+
self.lit_panel.run()
180+
175181
def configure_layout(self):
176182
return {"name": "home", "content": self.lit_panel}
177183
@@ -190,7 +196,7 @@ The second step, is to tell the Root component in which tab to render this compo
190196
In this case, we render the ``LitPanel`` UI in the ``home`` tab of the app.
191197

192198
.. code:: python
193-
:emphasize-lines: 16-17
199+
:emphasize-lines: 19-20
194200
195201
import lightning as L
196202
from lightning.app.frontend.panel import PanelFrontend
@@ -207,9 +213,14 @@ In this case, we render the ``LitPanel`` UI in the ``home`` tab of the app.
207213
super().__init__()
208214
self.lit_panel = LitPanel()
209215
216+
def run(self):
217+
self.lit_panel.run()
218+
210219
def configure_layout(self):
211220
return {"name": "home", "content": self.lit_panel}
212221
222+
app = L.LightningApp(LitApp())
223+
213224
----
214225

215226
*************

docs/source-app/workflows/add_web_ui/streamlit/basic.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,24 @@ First **create a file named app.py** with the app content:
3939
4040
# app.py
4141
import lightning as L
42+
import lightning.app.frontend as frontend
4243
import streamlit as st
4344
4445
def your_streamlit_app(lightning_app_state):
4546
st.write('hello world')
4647
4748
class LitStreamlit(L.LightningFlow):
4849
def configure_layout(self):
49-
return L.app.frontend.StreamlitFrontend(render_fn=your_streamlit_app)
50+
return frontend.StreamlitFrontend(render_fn=your_streamlit_app)
5051
5152
class LitApp(L.LightningFlow):
5253
def __init__(self):
5354
super().__init__()
5455
self.lit_streamlit = LitStreamlit()
5556
57+
def run(self):
58+
self.lit_streamlit.run()
59+
5660
def configure_layout(self):
5761
tab1 = {"name": "home", "content": self.lit_streamlit}
5862
return tab1
@@ -114,24 +118,28 @@ Link this function to the Lightning App by using the ``StreamlitFrontend`` class
114118
the ``configure_layout`` method of the Lightning component you want to connect to Streamlit.
115119

116120
.. code:: python
117-
:emphasize-lines: 8-10
121+
:emphasize-lines: 9-11
118122
119123
# app.py
120124
import lightning as L
125+
import lightning.app.frontend as frontend
121126
import streamlit as st
122127
123128
def your_streamlit_app(lightning_app_state):
124129
st.write('hello world')
125130
126131
class LitStreamlit(L.LightningFlow):
127132
def configure_layout(self):
128-
return L.app.frontend.StreamlitFrontend(render_fn=your_streamlit_app)
133+
return frontend.StreamlitFrontend(render_fn=your_streamlit_app)
129134
130135
class LitApp(L.LightningFlow):
131136
def __init__(self):
132137
super().__init__()
133138
self.lit_streamlit = LitStreamlit()
134139
140+
def run(self):
141+
self.lit_streamlit.run()
142+
135143
def configure_layout(self):
136144
tab1 = {"name": "home", "content": self.lit_streamlit}
137145
return tab1
@@ -149,24 +157,28 @@ The second step, is to tell the Root component in which tab to render this compo
149157
In this case, we render the ``LitStreamlit`` UI in the ``home`` tab of the application.
150158

151159
.. code:: python
152-
:emphasize-lines: 18
160+
:emphasize-lines: 22
153161
154162
# app.py
155163
import lightning as L
164+
import lightning.app.frontend as frontend
156165
import streamlit as st
157166
158167
def your_streamlit_app(lightning_app_state):
159168
st.write('hello world')
160169
161170
class LitStreamlit(L.LightningFlow):
162171
def configure_layout(self):
163-
return L.app.frontend.StreamlitFrontend(render_fn=your_streamlit_app)
172+
return frontend.StreamlitFrontend(render_fn=your_streamlit_app)
164173
165174
class LitApp(L.LightningFlow):
166175
def __init__(self):
167176
super().__init__()
168177
self.lit_streamlit = LitStreamlit()
169178
179+
def run(self):
180+
self.lit_streamlit.run()
181+
170182
def configure_layout(self):
171183
tab1 = {"name": "home", "content": self.lit_streamlit}
172184
return tab1

docs/source-app/workflows/add_web_ui/streamlit/intermediate.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ To modify the variables of a Lightning component, access the ``lightning_app_sta
1616
For example, here we increase the count variable of the Lightning Component every time a user presses a button:
1717

1818
.. code:: python
19-
:emphasize-lines: 7, 13
19+
:emphasize-lines: 8, 14
2020
2121
# app.py
2222
import lightning as L
23+
import lightning.app.frontend as frontend
2324
import streamlit as st
2425
2526
@@ -35,14 +36,17 @@ For example, here we increase the count variable of the Lightning Component ever
3536
self.count = 0
3637
3738
def configure_layout(self):
38-
return L.app.frontend.StreamlitFrontend(render_fn=your_streamlit_app)
39+
return frontend.StreamlitFrontend(render_fn=your_streamlit_app)
3940
4041
4142
class LitApp(L.LightningFlow):
4243
def __init__(self):
4344
super().__init__()
4445
self.lit_streamlit = LitStreamlit()
4546
47+
def run(self):
48+
self.lit_streamlit.run()
49+
4650
def configure_layout(self):
4751
tab1 = {"name": "home", "content": self.lit_streamlit}
4852
return tab1
@@ -61,10 +65,11 @@ parent component.
6165
In this example we update the value of the counter from the component:
6266

6367
.. code:: python
64-
:emphasize-lines: 6, 14
68+
:emphasize-lines: 7, 15
6569
6670
# app.py
6771
import lightning as L
72+
import lightning.app.frontend as frontend
6873
import streamlit as st
6974
7075
@@ -81,7 +86,7 @@ In this example we update the value of the counter from the component:
8186
self.count += 1
8287
8388
def configure_layout(self):
84-
return L.app.frontend.StreamlitFrontend(render_fn=your_streamlit_app)
89+
return frontend.StreamlitFrontend(render_fn=your_streamlit_app)
8590
8691
8792
class LitApp(L.LightningFlow):

0 commit comments

Comments
 (0)