voila-dashboards / voila

Voilà turns Jupyter notebooks into standalone web applications
https://voila.readthedocs.io
Other
5.48k stars 504 forks source link

Panel Tabulator on_click() and on_edit() callbacks not working in Voila #1435

Open Kalandoros opened 11 months ago

Kalandoros commented 11 months ago

First of all thanks for this great project. I'm using voila quite heavily and I like how seamless a notebook can be shown as some kind of application. I hope the project persists for still a long time. Also thanks advance for helping with the issue.

Description

Using the Panel Tabulator to represent tables conveniently, since it offers a lot of customizations, I noticed the following. To get back the clicked row and content of table cells or to get back the changed values when cells are edited for further processing the (on_click() and on edit() are used. Comparing the behavior of the callbacks between JupyterLab and Voila I noticed, that the callbacks (on_click() and on edit()) are not working in Voila. I might be wrong but due to the reason it works in JupyterLab, I would assume there is something to improve in Voila. For better explanation and demonstration I recorded the gif that shows the different behavior.

Animation

Reproduce

To reproduce I created a minimum example as follows:

Cell1

import panel as pn
import pandas as pd
from ipywidgets import *
pn.extension('tabulator', log_level='DEBUG', console_output='replace')

list_event = []

def bad_callback(event):
    print(event)
    list_event.append(event)

debug_view = widgets.Output(layout={'border': '1px solid black'})

@debug_view.capture(clear_output=True)
def get_list(e):
    print(list_event)

tabulator = pn.widgets.Tabulator(pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}), disabled=False)
tabulator.on_click(bad_callback)
tabulator.on_edit(bad_callback)
tabulator

Cell2

button = widgets.Button(description='click me to get the list of click events', layout={'width': '300px'})
button.on_click(get_list)
button

Cell3

debug_view
  1. Executing the cells in JupyterLab it can be seen, that after clicking random table cells or edit those, the event information of the callsbacks are stored in the list_event and represented by clicking the button click me to get the list of click events
  2. Doing the same in Voila nothing happens and the list list_event stays empty assuming the callback are not working in Voila.

Expected behavior

I would appreciate getting back the clicked row and content of table cells or getting back the changed values when cells are edited for further processing by using the (on_click() and on edit() methods as it does in JupyterLab.

Context

Troubleshoot Output
$PATH:
        C:\Users\xxx\anaconda3\envs\DevGround
        C:\Users\xxx\anaconda3\envs\DevGround\Library\mingw-w64\bin
        C:\Users\xxx\anaconda3\envs\DevGround\Library\usr\bin
        C:\Users\xxx\anaconda3\envs\DevGround\Library\bin
        C:\Users\xxx\anaconda3\envs\DevGround\Scripts
        C:\Users\xxx\anaconda3\envs\DevGround\bin
        C:\Users\xxx\anaconda3\condabin
        C:\Program Files (x86)\VMware\VMware Workstation\bin
        C:\Windows\system32
        C:\Windows
        C:\Windows\System32\Wbem
        C:\Windows\System32\WindowsPowerShell\v1.0
        C:\Windows\System32\OpenSSH
        C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
        C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
        C:\WINDOWS\system32
        C:\WINDOWS
        C:\WINDOWS\System32\Wbem
        C:\WINDOWS\System32\WindowsPowerShell\v1.0
        C:\WINDOWS\System32\OpenSSH
        C:\Program Files\Git\cmd
        C:\JupyterLab
        C:\Users\xxx\AppData\Local\Microsoft\WindowsApps
        C:\Users\xxx\AppData\Local\GitHubDesktop\bin

sys.path:
        C:\Users\xxx\anaconda3\envs\DevGround\Scripts
        C:\Users\xxx\anaconda3\envs\DevGround\python311.zip
        C:\Users\xxx\anaconda3\envs\DevGround\DLLs
        C:\Users\xxx\anaconda3\envs\DevGround\Lib
        C:\Users\xxx\anaconda3\envs\DevGround
        C:\Users\xxx\anaconda3\envs\DevGround\Lib\site-packages
        C:\Users\xxx\anaconda3\envs\DevGround\Lib\site-packages\win32
        C:\Users\xxx\anaconda3\envs\DevGround\Lib\site-packages\win32\lib
        C:\Users\xxx\anaconda3\envs\DevGround\Lib\site-packages\Pythonwin

sys.executable:
        C:\Users\xxx\anaconda3\envs\DevGround\python.exe

sys.version:
        3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)]

platform.platform():
        Windows-10-10.0.22631-SP0

where jupyter:
        C:\Users\xxx\anaconda3\envs\DevGround\Scripts\jupyter.exe

pip list:
        Package                           Version
        --------------------------------- ------------
        affine                            2.4.0
        aniso8601                         9.0.1
        anyio                             4.0.0
        argon2-cffi                       21.3.0
        argon2-cffi-bindings              21.2.0
        arrow                             1.3.0
        asttokens                         2.0.5
        async-lru                         2.0.4
        attrs                             23.1.0
        Babel                             2.13.0
        backcall                          0.2.0
        beautifulsoup4                    4.12.2
        bleach                            6.1.0
        blinker                           1.6.2
        bokeh                             3.2.2
        bqplot                            0.12.40
        branca                            0.6.0
        brotlipy                          0.7.0
        cachelib                          0.9.0
        cachetools                        5.3.1
        certifi                           2023.7.22
        cffi                              1.15.1
        chardet                           5.2.0
        charset-normalizer                2.0.4
        click                             8.1.7
        click-plugins                     1.1.1
        cligj                             0.7.2
        colorama                          0.4.6
        comm                              0.1.4
        contourpy                         1.0.5
        cryptography                      41.0.3
        cycler                            0.11.0
        debugpy                           1.6.7
        decorator                         5.1.1
        defusedxml                        0.7.1
        docxcompose                       1.4.0
        docxtpl                           0.16.7
        et-xmlfile                        1.1.0
        executing                         0.8.3
        fastjsonschema                    2.18.1
        Fiona                             1.9.4.post1
        Flask                             2.3.3
        Flask-Caching                     2.1.0
        Flask-Cors                        4.0.0
        flask-restx                       1.1.0
        folium                            0.14.0
        fonttools                         4.25.0
        fqdn                              1.5.1
        gast                              0.4.0
        geographiclib                     2.0
        geopandas                         0.14.0
        geopy                             2.4.0
        h11                               0.14.0
        idna                              3.4
        ipydatagrid                       1.2.0
        ipykernel                         6.25.0
        ipyleaflet                        0.17.4
        ipympl                            0.9.3
        ipython                           8.15.0
        ipython-genutils                  0.2.0
        ipywebrtc                         0.6.0
        ipywidgets                        8.1.1
        isoduration                       20.11.0
        itsdangerous                      2.1.2
        jedi                              0.18.1
        Jinja2                            3.1.2
        json5                             0.9.14
        jsonpointer                       2.4
        jsonschema                        4.19.1
        jsonschema-specifications         2023.7.1
        jupyter-bokeh                     3.0.7
        jupyter_client                    8.1.0
        jupyter_core                      5.3.0
        jupyter-events                    0.7.0
        jupyter-lsp                       2.2.0
        jupyter_server                    2.7.3
        jupyter_server_terminals          0.4.4
        jupyterlab                        4.0.6
        jupyterlab-pygments               0.2.2
        jupyterlab_server                 2.25.0
        jupyterlab-widgets                3.0.9
        kiwisolver                        1.4.4
        large-image                       1.25.0
        large-image-source-rasterio       1.25.0
        lckr_jupyterlab_variableinspector 3.1.0
        linkify-it-py                     2.0.2
        localtileserver                   0.7.2
        lxml                              4.9.3
        Markdown                          3.5
        markdown-it-py                    3.0.0
        MarkupSafe                        2.1.1
        matplotlib                        3.7.2
        matplotlib-inline                 0.1.6
        mdit-py-plugins                   0.4.0
        mdurl                             0.1.2
        mistune                           3.0.2
        mkl-fft                           1.3.8
        mkl-random                        1.2.4
        mkl-service                       2.4.0
        munkres                           1.1.4
        nbclient                          0.7.4
        nbconvert                         7.9.2
        nbformat                          5.9.1
        nest-asyncio                      1.5.6
        notebook_shim                     0.2.3
        numpy                             1.26.0
        openpyxl                          3.2.0b1
        outcome                           1.2.0
        overrides                         7.4.0
        packaging                         23.1
        palettable                        3.3.3
        pandas                            2.1.1
        pandocfilters                     1.5.0
        panel                             1.3.6
        param                             2.0.1
        parso                             0.8.3
        pickleshare                       0.7.5
        Pillow                            10.0.1
        pip                               23.2.1
        platformdirs                      3.10.0
        plotly                            5.17.0
        ply                               3.11
        prometheus-client                 0.17.1
        prompt-toolkit                    3.0.36
        psutil                            5.9.0
        pure-eval                         0.2.2
        py2vega                           0.6.1
        pycparser                         2.21
        Pygments                          2.15.1
        pyOpenSSL                         23.2.0
        pyparsing                         3.0.9
        pyproj                            3.6.1
        PyQt5                             5.15.7
        PyQt5-sip                         12.11.0
        PySocks                           1.7.1
        python-dateutil                   2.8.2
        python-docx                       1.1.0
        python-json-logger                2.0.7
        pytz                              2023.3.post1
        pyviz_comms                       3.0.0
        pywin32                           305.1
        pywinpty                          2.0.12
        PyYAML                            6.0.1
        pyzmq                             25.1.0
        QtPy                              2.4.1
        rasterio                          1.3.8.post1
        referencing                       0.30.2
        requests                          2.31.0
        rfc3339-validator                 0.1.4
        rfc3986-validator                 0.1.1
        rpds-py                           0.10.4
        scipy                             1.11.3
        scooby                            0.7.4
        seaborn                           0.13.0
        selenium                          4.14.0
        Send2Trash                        1.8.2
        server-thread                     0.2.0
        setuptools                        68.0.0
        shapely                           2.0.1
        sip                               6.6.2
        six                               1.16.0
        sniffio                           1.3.0
        snuggs                            1.4.7
        sortedcontainers                  2.4.0
        soupsieve                         2.5
        stack-data                        0.2.0
        tenacity                          8.2.3
        terminado                         0.17.1
        tinycss2                          1.2.1
        toml                              0.10.2
        tornado                           6.3.2
        tqdm                              4.66.1
        traitlets                         5.11.2
        traittypes                        0.2.1
        trio                              0.22.2
        trio-websocket                    0.11.1
        types-python-dateutil             2.8.19.14
        typing_extensions                 4.7.1
        tzdata                            2023.3
        uc-micro-py                       1.0.2
        uri-template                      1.3.0
        urllib3                           1.26.16
        uvicorn                           0.23.2
        voila                             0.5.5
        wcwidth                           0.2.5
        webcolors                         1.13
        webencodings                      0.5.1
        websocket-client                  1.6.4
        websockets                        11.0.3
        Werkzeug                          3.0.0
        wheel                             0.41.2
        widgetsnbextension                4.0.9
        win-inet-pton                     1.1.0
        wsproto                           1.2.0
        xyzservices                       2023.10.0

If using JupyterLab

Installed Labextensions
        bqplot v0.5.41 enabled  X (python, bqplot)
        ipydatagrid v1.2.0 enabled ok
        jupyter-leaflet v0.17.4 enabled ok
        jupyter-matplotlib v0.11.3 enabled ok
        jupyter-webrtc v0.6.0 enabled ok
        jupyterlab-plotly v5.17.0 enabled  X
        jupyterlab_pygments v0.2.2 enabled  X (python, jupyterlab_pygments)
        @bokeh/jupyter_bokeh v3.0.7 enabled  X (python, jupyter_bokeh)
        @jupyter-widgets/jupyterlab-manager v5.0.9 enabled ok (python, jupyterlab_widgets)
        @lckr/jupyterlab_variableinspector v3.1.0 enabled ok (python, lckr_jupyterlab_variableinspector)
        @pyviz/jupyterlab_pyviz v3.0.0 enabled ok
        @voila-dashboards/jupyterlab-preview v2.3.5 enabled ok (python, voila)
Kalandoros commented 10 months ago

It's just a guess and please prove me wrong but on the browser console I found the following that might be interesting Failed to create module: package: @pyviz/jupyterlab_pyviz; module: ./extension: image

Might that be the problem?

Kalandoros commented 6 months ago

There are a couple of reports which are related to this issue. Since it is workign fine on JupyterLab but not on Voila I guess the root case might be somewhere in voila.

https://github.com/holoviz/panel/issues/6731 https://github.com/holoviz/panel/issues/3963 https://github.com/bokeh/jupyter_bokeh/issues/201

Kalandoros commented 4 months ago

Further I found several issues that might be also related this issue. It might help to find some correlations between the issues or find the root case.

https://github.com/voila-dashboards/voila/issues/244 https://github.com/holoviz/panel/issues/1341 https://github.com/voila-dashboards/voila/issues/244#issuecomment-623783437 https://github.com/jupyter-widgets/ipywidgets/issues/3902

I guess they this is all related to each other, which seems to have something to do with jupyter_bokeh . It has been found here as well an might be helpful: https://github.com/bokeh/jupyter_bokeh/issues/201 image

Using pn.extension(comms='ipywidgets') as announced https://github.com/voila-dashboards/voila/issues/244#issuecomment-623783437 will result in [Open Browser Console for more detailed log - Double click to close this message] Failed to load model class 'BokehModel' from module '@bokeh/jupyter_bokeh' Error: No version of module @bokeh/jupyter_bokeh is registered

It seems there is a whole collection that is related to this.

@philippjfr Do you think this is a correct assumption? Is there a current workaround for this?

Kalandoros commented 3 months ago

The issue is reported at https://github.com/bokeh/jupyter_bokeh/issues/201#issuecomment-2271590207 as well. @bryevdv: FYI

It is just to put the correlated issues together and having it easier to find the root cause.