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

Improve notebook resource and extension loading #4752

Merged
merged 9 commits into from
May 2, 2023
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented May 1, 2023

In the past we had two major issues with resource and extension loading in notebooks.

Problems

Multiple extension calls

To avoid embedding huge inline JS/CSS bundles multiple times we avoided embedding the extension multiple times. This however caused issues if you had multiple extension calls in one cell, e.g.:

import hvplot.pandas
pn.extension('tabulator')

OR

import holoviews as hv
hv.extension('bokeh')
pn.extension('tabulator')

Properly educating users on these issues is basically impossible and it adds significant friction.

Version clashes

When a user upgrades from an older Bokeh/Panel version the autoload JS code would detect that an existing Bokeh version is present and skip loading of the newer Bokeh and Panel libraries. Since newer Bokeh model bundles rarely work with older Bokeh/Panel JS versions this would lead to an error and no output showing up.

This situation could occur both in JupyterLab, where multiple tabs could load different versions of Bokeh and therefore you would have to potentially clear out all existing notebooks (and reload the page) when upgrading to a new Bokeh/Panel version. However even in classic notebook you could run into this situation by opening an existing notebook which had an older version of the autoload JS code embedded into it.

The solution

Instead of skipping the autoload JS code when multiple extensions are run we instead always run it but do not include Bokeh and Panel bundles when run a second time. This means extra extensions can be loaded in a secondary call to the extension without including the entire bundle each time.

Additionally we now check that the Bokeh JS version matches what we expect and if it does not we go ahead and load the newer Bokeh/Panel bundles. Once loaded we restore the old version BUT store the newer versions in a Bokeh.versions object. When a component is rendered we then look up the correct Bokeh version to use for rendering.

  • Fix for non-inlined Bokeh/Panel resources

@philippjfr
Copy link
Member Author

pre-commit.ci autofix

@codecov
Copy link

codecov bot commented May 1, 2023

Codecov Report

Merging #4752 (fe5579c) into main (02e215a) will decrease coverage by 0.17%.
The diff coverage is 36.36%.

@@            Coverage Diff             @@
##             main    #4752      +/-   ##
==========================================
- Coverage   83.29%   83.12%   -0.17%     
==========================================
  Files         268      268              
  Lines       37708    37709       +1     
==========================================
- Hits        31409    31346      -63     
- Misses       6299     6363      +64     
Flag Coverage Δ
ui-tests 39.70% <22.72%> (-1.01%) ⬇️
unitexamples-tests 73.19% <36.36%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
panel/models/comm_manager.py 52.38% <0.00%> (ø)
panel/config.py 70.61% <30.00%> (+1.47%) ⬆️
panel/io/resources.py 83.16% <42.85%> (-0.79%) ⬇️
panel/io/notebook.py 43.42% <50.00%> (ø)

... and 8 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

panel/io/notebook.py Outdated Show resolved Hide resolved
@philippjfr philippjfr added this to the v1.0.0 milestone May 2, 2023
@philippjfr philippjfr requested a review from hoxbro May 2, 2023 11:18
Copy link
Member

@hoxbro hoxbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the code, still need to test it.

panel/_templates/autoload_panel_js.js Outdated Show resolved Hide resolved
panel/_templates/autoload_panel_js.js Show resolved Hide resolved
panel/io/notebook.py Show resolved Hide resolved
panel/io/resources.py Show resolved Hide resolved
panel/_templates/autoload_panel_js.js Show resolved Hide resolved
panel/_templates/doc_nb_js.js Show resolved Hide resolved
@hoxbro
Copy link
Member

hoxbro commented May 2, 2023

I have tested in a variety of combinations of Notebook/Lab/vscode both with this PR and Panel 0.14. Where Panel 0.14 fails, this succeeds. Using an old notebook with Panel 0.14 loaded beforehand now loads correctly with this PR.

The problem with the ordering of hv.extension and pn.extension did not occur either.

@philippjfr philippjfr force-pushed the notebook_handling branch from c4543cc to fe5579c Compare May 2, 2023 13:32
@philippjfr philippjfr merged commit 90acf17 into main May 2, 2023
@philippjfr philippjfr deleted the notebook_handling branch May 2, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants