如何在bokeh中使用“OpenURL”打开绝对url?

2024-09-27 07:26:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的代码,它在(1.0,1.0)处绘制一个点。我希望能够单击此点打开由指定的url属性指定的页面的浏览器:

from bokeh.plotting import figure
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource, TapTool, OpenURL

import pandas as pd

df = pd.DataFrame({"x": [1.0], "y": [1.0], "url": ["https://www.google.com"]})

datasource = ColumnDataSource(df)

fig = figure(
    title='test',
    plot_width=600,
    plot_height=600,
    tools=('pan, wheel_zoom, reset, tap')
)

p = fig.select(type=TapTool)
p.callback = OpenURL(url="@url")

fig.circle(
    'x',
    'y',
    source=datasource,
    line_alpha=0.6,
    fill_alpha=0.6,
    size=10
)

curdoc().add_root(fig)

但是,当我运行应用程序并单击该点时,一个新选项卡将打开http://localhost:5006/https%3A%2F%2Fwww.google.com,这似乎表明bokeh想要打开相对于tornado服务器的URL。如何简单地打开绝对URL而不是相对URL


Tags: fromimportcomurldfgooglebokehfig

热门问题