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

Patch to make tabulator work offline in jupyter notebook in "pn.config.inline" mode #6607

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pankajp
Copy link

@pankajp pankajp commented Mar 29, 2024

  • io/notebook.py render_mimebundle defaults to resources=inline when pn.config.inline=True instead of always using cdn
  • In this mode, we patch the doc json to replace ImportedStyleSheet with InlineStyleSheet
  • io/resources.py patches loading of inlined js file to make require defines work in cases where the define() call has the module name not specified
  • layout.ts: watch_stylesheets() makes sure to call "style_redraw()" in case no css link needs to be loaded. This is done after a timeout since some models (eg Tabulator) aren't completely setup when the watch_stylesheets() call is made.

Testing:
In jupyter notebook (I'm using classic notebook):

import panel as pn
print(pn, pn.__version__)
pn.extension('tabulator', 'plotly', inline=True)
import pandas as pd
df = pd.DataFrame({'a':range(10), 'b':[chr(ord('A')+i) for i in range(10)]})
pn.widgets.Tabulator(df)

Fixes #3959
xref: #5167

Note: This is a POC code to share the minimal conceptual changes needed to make panel tabulator work offline in notebook. Took me a while to get this working, so posting it here for review and "inspiration" to get a proper fix in panel, as it seems we have quite a few github issues about problems working offline

- notebook `render_mimebundle` defaults to resources=inline when pn.config.inline=True instead of always using cdn
- In this mode, we patch the doc json to replace ImportedStyleSheet with InlineStyleSheet
- resources.py patches loading of inlined js file to make require defines work in cases where the define() call has the module name not specified
- layout.ts: watch_stylesheets() makes sure to call "style_redraw()" in case no css link needs to be loaded. This is done after a timeout since some models (eg Tabulator) aren't completely setup when the watch_stylesheets() call is made.
@philippjfr
Copy link
Member

Thanks for digging into this. I'll have to untangle these changes a little bit.

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.

tabulator doesn't work in an offline notebook context
2 participants