Link custom javascript

Sorry for the first post, i read bad.

For trigger a Python callback I use a bokeh Slider, because you can have that object in javascript identified by its name with Bokeh.documents[0].get_model_by_name(“dummy_slider”).
There is a Issue in panel to expose the names, but I think it is not solved.
Note that I delete the button, if you have a button and a custom callback you can use the args as in your example and it is more easy the solution, but not so practical. With the html element you can send a “”"<script></script>""" where you can define all the JS functions you want, transparent for the user.

With the slider I look the index of the table clicked, and set the value of whatever I want with the help of the slider value. It is a hacky solution, but it works perfectly for me.

import panel as pn
from bokeh.sampledata.autompg import autompg
from bokeh.models import  Slider

slider = Slider(name="dummy_slider", visible=False, value=0, start=0, end=100000000)

js = {'$': 'https://code.jquery.com/jquery-3.4.1.slim.min.js',}
pn.extension(js_files=js)

html = autompg.head(10).to_html(classes=['example', 'panel-df'])

comm_js_py = pn.widgets.StaticText(name='selected_ids',value='')#style={'visibility': 'hidden', 'width': 0, 'height': 0, 'overflow': 'hidden'}, margin=0)

JS_code = """<script> 
slider = Bokeh.documents[0].get_model_by_name("dummy_slider");
    
$(".example td").click(function(event) {
    slider.value = parseFloat(this.parentElement.firstElementChild.textContent);
    console.log('clicked', this.textContent, this.parentElement);
    trigger_element = this.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.firstElementChild
    trigger_element.textContent = this.textContent;
    })
</script>
"""

html += JS_code


# ouput div to write some information retrieve on python side
output_div = pn.widgets.StaticText(width=500, value='abc')

# @pn.depends(comm_js_py, watch=True)
def update_output(attr, old, new):
    print (attr, old, new, slider.value)
    output_div.value += str(old) + str(autompg.loc[slider.value]) + '<br>'

slider.on_change("value", update_output)

pn.Column( comm_js_py, slider, pn.Row(html, output_div),  sizing_mode="stretch_width").show()