Context_menu does not work for Tabulator

import pandas as pd
import panel as pn

raw_data = \
[
  {
    "value": 'A',
    "frequency": 3
  },
  {
    "value": 'B',
    "frequency": 2
  },
  {
    "value": 'C',
    "frequency": 1
  },
  {
    "value": 'D',
    "frequency": 1
  },
  {
    "value": 'E',
    "frequency": 1
  },
  {
    "value": 'F',
    "frequency": 2
  },
]

def contextMenu():
    print("Selected Option One from context menu...")

value_freq = pd.DataFrame(raw_data)
tabWid = pn.widgets.Tabulator(value_freq, configuration={
                                                            'rowContextMenu':[
                                                                {
                                                                    'label':'Option One',
                                                                    'action':contextMenu()
                                                        
                                                                },
                                                                {
                                                                    'separator':True
                                                                },
                                                            ]
                                                        })
pn.Row(tabWid).servable()

It is observed that the context menu appears on right click but the function is not called.

contextMenu() function is called at the very beginning for only once during initialization phase.

It would also be great if I get the cell value from where the context menu is used
for eg: If context menu is used from cell with value ā€˜Cā€™ then how do I get the value ā€˜Cā€™ā€¦??

(I know I can make use of selection feature to trigger a function whenever a cell is selected, but would like to know how context_menu can be implemented)

Thanks in advance.

2 Likes

Hi @xyz_panel

Welcome to the community. You will not be able to create a context menu currently. The configuration you specify will have to contain objects that can be serialized, sent to the browser and applied there. A function is not serializable.

If you need a context menu on the tabulator table please file a feature request on Github. Thanks.

2 Likes

Hi @Marc
Thanks for your reply.
I have raised a feature request on Github.