
I would like to display the figure name when the figure has been tapped on. My understanding of Bokeh and Java is that the this keyword in the code of CustomJS should refer to the object that was passed to it, which should be the figure fig2 in the CustomJS of the variable change_text in the code below. However, this seems incorrect as I cannot get the code to work.
What should be passed to the code of CustomJS in order to display the name attribute of fig2?
Edit: note that I don’t want to parse fig2 as an argument to CustomJS. The method I need has to be generalised and work for all figures on the page.
Here is the code (note the figure has no data to minimise code):
from bokeh.models import CustomJS
from bokeh.plotting import figure, output_file, show
from bokeh.models.widgets import Paragraph
from bokeh.events import Tap
from bokeh.layouts import column
fig2 = figure(name='fig2')
current_selection = Paragraph(text="")
change_text = CustomJS(code="current_selection.text = this.name")
change_text.args.update(dict(current_selection=current_selection))
fig2.js_on_event(Tap, change_text)
output_file("example.html", title="example")
show(column(fig2, current_selection))