I am using python3.10 with Bokeh2.4.3. My goal is to create a simple scatter plot with only a few points (around 10-15 data points). But if I click one of those data points, I want it to open a new tab with another plot i.e. each data point of the first plot is actually a link for other plots. I did add the hover functionality but cannot figure out how to add an onclick event such that when I am hovering if I click, it will open another Bokeh plot.
Here is what I tried:
from bokeh.plotting import figure, show, output_file, save
import pandas
from bokeh.models.tools import HoverTool
df = pandas.read_csv("list_of_all_five_data_file.csv")
df1 = pandas.read_csv("sample_data1.csv")
df2 = pandas.read_csv("sample_data2.csv")
df3 = pandas.read_csv("sample_data3.csv")
df4 = pandas.read_csv("sample_data4.csv")
df5 = pandas.read_csv("sample_data5.csv")
output_file("main.html")
plot = figure(title = "Main Plot")
plot.dot(x=[1, 2, 3, 4, 5],
y=[df["file_no"]])
hover = HoverTool()
hover.tooltips = """
<div>
Click to see this data
</div>
"""
plot.add_tools(hover)
show(plot)
Now, this will give me a plot with 5 dots. But I want that whenever I click on a certain dot, the following code for the corresponding dot will be run. For example, the code for datafile 1 will like like:
x1 = df1['x_values']
y1 = df1['y_values']
p1 = figure(title = "This is data1 plot")
p1.scatter(x1, y1)
show(plot)
Likewise, there will be code for other data files too. My main question is how to add this onclick functionality? Also, is there any shorter way to do this because if the number of the data files increases, then this code will be very nasty and big.