holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.83k stars 519 forks source link

Panel Tabulator selection not working within jupyter directly, but does using pn.serve #4269

Closed krlng closed 1 year ago

krlng commented 1 year ago

Example Code:

import panel as pn
pn.extension('tabulator',"plotly")

import datetime as dt
import numpy as np
import pandas as pd
import panel as pn

np.random.seed(7)
pn.extension('tabulator')

from logging import getLogger
l = getLogger()
sel_df = pd.DataFrame(np.random.randn(3, 5), columns=list('ABCDE'))

select_table = pn.widgets.Tabulator(sel_df, disabled=True)

def click(event):
    l.error(event)
    print(f'Clicked cell in {event.column!r} column, row {event.row!r} with value {event.value!r}')

select_table.on_click(click) 

select_table

If I click in the resulting table, nothing gets printed. Also select_table.selection stays an empty array.

How ever if I use pn.serve(select_table and click things there, it does work.

Think this might be related to this closed issue.

Using Python 3.10.9 and panel==0.14.1. Can give you the full pyproject.toml if you need it.

hoxbro commented 1 year ago

It seems to work for me. Can you try to upgrade to Panel 0.14.2?

image

krlng commented 1 year ago

No, upgrading did not help. I now also tried with a custom fresh environment, no change. JupyterLab 3.5.2. Anything else I might check?

[tool.poetry]
name = "debug-panel"
version = "0.1.0"
description = ""
authors = ["Nico Kreiling <nico.kreiling@gmail.com>"]
readme = "README.md"
packages = [{include = "debug_panel"}]

[tool.poetry.dependencies]
python = "^3.10"
panel = "^0.14.2"
pandas = "^1.5.2"
ipykernel = "^6.20.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

poetry.lock file attached (just renamed to pass githubs file-type-filter): poetry.lock

philippjfr commented 1 year ago

Could you try clearing your notebook, saving it and reloading the page (and if you're in JupyterLab close all other notebooks). That sometimes helps.

krlng commented 1 year ago

I just restarted my whole computer => No help.

Ran the notebook within Colab => Works Ran the notebook within VsCode locally => Works

I also found out in the meantime, that non of the interactive elements (such as @depends) work within my jupyterlab. Also tried to uninstall and reinstall jupyterlab and ipywidgets, without success.

Pretty sure this is not a direct panel issue but rather something within the dependencies, so feel free to close it. How ever I am very thankful for any ideas.

philippjfr commented 1 year ago

Just looked at the code you pasted again, could you try one more thing for me and only use one pn.extension call and split it across two cells like this:

Cell 1:

import panel as pn

import datetime as dt
import numpy as np
import pandas as pd
import panel as pn

np.random.seed(7)
pn.extension('tabulator',"plotly")

Cell 2

from logging import getLogger
l = getLogger()
sel_df = pd.DataFrame(np.random.randn(3, 5), columns=list('ABCDE'))

select_table = pn.widgets.Tabulator(sel_df, disabled=True)

def click(event):
    l.error(event)
    print(f'Clicked cell in {event.column!r} column, row {event.row!r} with value {event.value!r}')

select_table.on_click(click) 

select_table
krlng commented 1 year ago

Also does not help :( Simple no print out

philippjfr commented 1 year ago

Sorry we weren't able to help here. I'll close but please chime in if you identify what the issue was.

oldrichsmejkal commented 1 year ago

This issue seems to be still present (panel version '0.14.4') Any ideas how to debug?

philippjfr commented 1 year ago

I'll tag 1.0.0rc2 shortly, if you could try that when it's available that would be super helpful.

jackhhchan commented 1 year ago

Hi, I was also having this issue but after some investigating I think the dependency pyviz_comms maybe missing.

https://github.com/holoviz/panel/issues/1347#issuecomment-632839307 https://github.com/holoviz/panel/issues/1873#issuecomment-751519693

  1. pip install pyviz_comms
    pip install --upgrade pyviz_comms
  2. restart jupyter lab.

Note: I have also tried to install 1.0.0rc2 but i'm running an issue with building the wheels. ( i am not sure why - also not familiar with how wheels work for python)

pip install git+https://github.com/holoviz/panel.git@v1.0.0rc2
...
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for panel
Failed to build panel
ERROR: Could not build wheels for panel, which is required to install pyproject.toml-based projects

Now it all seem to work for me:

image

Hope this helps!

jupyterlab==3.6.3 pyviz-comms==2.2.1 Python 3.9.6

hoxbro commented 1 year ago

Panel has to build javascript when installing it from source (which needs Node JS installed). The way to easily test pre-releases is with pip install panel==1.0 --pre or conda install panel=1.0 -c pyviz/channel/dev

JeffSaxeVA commented 8 months ago

This issue is closed (months ago), with the solution being that the pyviz_comms package needed to be a dependency of panel at installation time. Thank you for fixing that, but in case anyone is Googling for this symptom in the future, I wanted to state with some embarrassment one more possible root cause for this exact issue, which I just fixed today: disabling (and forgetting that you disabled) the jupyterlab_pyviz LabExtension that is critical to getting the JavaScript in the browser talking to the backend Python in the Jupyter server!

Some months ago, we had a different problem which I can't even remember now, and in the course of troubleshooting that issue, we found that we could put in a user-home-directory-specific JSON file ~/.jupyter/labconfig/page_config.json with a few lines

{ "disabledExtensions": { "@pyviz/jupyterlab_pyviz": "true", "anotherextension": "true", "somethirdextension": "true" } }

to disable 3 specific LabExtensions, and refresh the Lab browser window, and then that problem would go away. If we run jupyter labextension list in a Terminal tab, we can clearly see the ones that are being suppressed from loading.

So of course we forgot about this workaround, and now, months later, we couldn't get the Panel Tabulator object to trigger any backend handler functions — neither with .on_click() nor with .param.watch(...,'selection'). Once we un-disabled the LabExtensions, everything is working normally.