mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
740 stars 55 forks source link

Interactive tables don't work in notebooks executed with "jupytext --execute" #80

Closed mwouts closed 2 years ago

mwouts commented 2 years ago

For instance, if I run

jupytext --to ipynb advanced_parameters.md --execute

on this document, and then open the resulting .ipynb file, no interactive table is displayed.

If I open and re-execute the notebook in another editor (here VS Code), the interactive tables works. The diff between the version generated by jupytext --execute and VS Code is limited to the outputs of the init_notebook_mode cell:

The version that fails has a list of string in "application/javascript"

"outputs": [
    {
     "data": {
      "application/javascript": [
       "/*! jQuery v3.6.0 | (c) OpenJS Foundation and other contributors | jquery.org/license */\n",
       "!function(e,t) (...)

while the version that works has a single string in "application/javascript":

"outputs": [
    {
     "data": {
      "application/javascript": "/*! jQuery v3.6.0 | (c) OpenJS Foundation and other contributors | jquery.org/license */\n!function(e,t)

image

mwouts commented 2 years ago

The long string seems to be VS Code's way to store Javascript outputs. The list of strings is compliant with Jupyter Lab's export, so maybe the failing display of notebooks executed with either jupytext or nbconvert in VS Code is due to a non-standard handling of outputs in VS Code.

Now, when I open a notebook executed with Jupytext or NBconvert (same outcome) in Jupyter Lab, the outputs for the first cell are displayed as

<IPython.core.display.Javascript object>

and the interactive tables just show "Loading ...". This appears to be a different issue - the notebook is not trusted so Javascript is not allowed. This is fixed when I execute "View / Activate Command Palette / Trust Notebook" in Jupyter Lab, probably because executing the notebook with either Jupytext or NBconvert does not add it to the list of trusted notebooks.