-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
Add ability to defer load until after page is rendered #3882
Conversation
@MarcSkovMadsen Give this one a go. For now it simply uses the |
Codecov Report
@@ Coverage Diff @@
## master #3882 +/- ##
=======================================
Coverage 82.83% 82.84%
=======================================
Files 215 216 +1
Lines 32385 32456 +71
=======================================
+ Hits 26826 26888 +62
- Misses 5559 5568 +9
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thanks for taking this seriously @philippjfr . I actually believe its the most important missing piece of the Panel api to make it easy to create data apps with a great look and feel. There are still a few things around I totally agree that by default we should use the same loading spinner as we use elsewhere. I will review now. |
Feedback 1Using the code example below I noticed a few thing.
panel-014-deferload.mp4import time
start = time.time()
import pandas as pd
import panel as pn
import hvplot.pandas
pn.extension(
sizing_mode='stretch_width', template='fast', defer_load=True,
loading_spinner='arc', loading_color='#0072B5'
)
count = pn.widgets.IntSlider(value=3, start=1, end=10, name="Count").servable(target="sidebar")
def big_load():
time.sleep(1)
return pd.DataFrame({"x": [1,2,3], "y": [1,2,3]})
def big_plot(count=3):
# time.sleep(2)
return pd.DataFrame({"x": range(0,count), "y": range(0,count)}).hvplot(height=100, xlim=(0,10))
@pn.depends(count)
def big_plot1(count=3):
return big_plot(count)
def duration():
time.sleep(3)
return time.time()-start
ibig_plot = pn.bind(big_plot, count=count)
layout= pn.Column(big_load, big_plot, big_plot1, ibig_plot, duration)
add = pn.widgets.Button(name="Add").servable(target="sidebar")
def add_panel(_):
print("update")
layout.append(pn.panel(ibig_plot))
add.on_click(add_panel)
layout.servable() |
Feedback 2In this example I would expect the value of the not-defer-load.mp4import time
start = time.time()
import pandas as pd
import panel as pn
import hvplot.pandas
pn.extension(
sizing_mode='stretch_width', template='fast', defer_load=True,
loading_spinner='arc', loading_color='#0072B5'
)
count = pn.widgets.IntSlider(value=3, start=1, end=10, name="Count").servable(target="sidebar")
def big_load():
time.sleep(3)
return pd.DataFrame({"x": [1,2,3], "y": [1,2,3]})
def duration_no_sleep():
return f"This text is important to show immediately {round(time.time()-start,2)}"
layout= pn.Column(big_load, pn.panel(duration_no_sleep, defer_load=False))
layout.servable() |
Feedback 3In this example I get the warnings below. I would not expect to get those. import time
start = time.time()
import pandas as pd
import panel as pn
import hvplot.pandas
pn.extension(
sizing_mode='stretch_width', template='fast',
loading_spinner='arc', loading_color='#0072B5'
)
count = pn.widgets.IntSlider(value=3, start=1, end=10, name="Count").servable(target="sidebar")
def big_load():
print("big_load")
time.sleep(2)
return pd.DataFrame({"x": [1,2,3], "y": [1,2,3]})
def duration():
print("duration")
time.sleep(2)
return f"This text is important to show immediately {round(time.time()-start,2)}"
layout= pn.Column(pn.panel(big_load, defer_load=False), pn.panel(duration, defer_load=True))
layout.servable() Warnings
UPDATE: Maybe its ok to get? |
Feedback 4In this example I would expect the spinner to be shown for 4 seconds. But its only there for a split second. spinner-only-shown-shortly.mp4import time
start = time.time()
import pandas as pd
import panel as pn
import hvplot.pandas
pn.extension(
sizing_mode='stretch_width', template='fast',
loading_spinner='arc', loading_color='#0072B5'
)
count = pn.widgets.IntSlider(value=3, start=1, end=10, name="Count").servable(target="sidebar")
def big_load():
print("big_load")
time.sleep(2)
return pd.DataFrame({"x": [1,2,3], "y": [1,2,3]})
def duration():
print("duration")
time.sleep(2)
return f"This text is important to show immediately {round(time.time()-start,2)}"
layout= pn.Column(pn.panel(big_load, defer_load=True), duration)
layout.servable() |
Thanks for testing, will look into the issues tonight. |
This is because the
Again, ordering matters, the
The warning comes from the callback without
Looking into this one, it does seem like a bug. |
Comment 1 - referring to Feedback 1 above This does not make sense to me: Comment 2 - referring to Feedback 2 above This does not make sense to me: I would expect to be able to specify some functions to be deferred ( BUT testing on the updated code I example in Feedback 2 it now works as I expect for the example from Feedback 2. General CommentThis now works really great for me. Should probably be tested more by others as well. And some pytest tests added. But its such an improvement for Panel makes it so much easier to make applications with a modern look and feel. Thanks. |
Yeah, clearly didn't study those examples enough. Thanks for double checking! |
Makes it possible to defer the loading of components until after the page is rendered. Can be used explicitly with
ParamMethod
andParamFunction
(or viapanel()
) OR by settingconfig.defer_load
.