2017-12-25 28 views
1

나는 여러 개의 그림이 그려져 있습니다. 나는 그것에 직사각형을 연결하고 싶으면. 비슷한 문서가 모든 플롯 링크를 만들지 만, 직사각형이 링크가 될 것입니다. js_on_event, costum_js_on_tap 등으로 생각의 파이썬 보케는 링크 플롯의 일부분을 만듭니다.

나는

예 시도 ... 많이 시도 :

... 
plot.line([1, seq_len], [-0.2, -0.2], color="black") 
callback = OpenURL(url="google.com") 
a = plot.rect(1, 1, 100, 1) 
a.js_on_event('tap', callback) 
... 

답변

2

아마 쉬운 방법이있다 그러나 이것은 나를 위해 작동 :

from bokeh.models import ColumnDataSource, TapTool,CustomJS 
from bokeh.plotting import figure 
from bokeh.embed import file_html 
from bokeh.resources import INLINE 

p = figure(plot_width=400, plot_height=400, 
      tools="tap", title="The rectangles are links") 

source1 = ColumnDataSource(data=dict(x1=[1],x2=[2],y1=[2],y2=[1],color=["navy"],url=["http://www.google.com"])) 
source2 = ColumnDataSource(data=dict(x1=[2],x2=[3],y1=[5],y2=[4],color=["orange"],url=["https://stackoverflow.com"])) 
source3 = ColumnDataSource(data=dict(x1=[3],x2=[4],y1=[8],y2=[7],color=["olive"],url=["https://bokeh.pydata.org"])) 

#glyphs with links 
p.quad('x1','x2','y1','y2',color='color',source=source1) 
p.quad('x1','x2','y1','y2',color='color',source=source2) 
p.quad('x1','x2','y1','y2',color='color',source=source3) 

#glyph without a link 
p.circle(5, 5, size=20) 

jscode=""" 
s=cb_data.source; 
atr=s.attributes; 
var d=atr.data;//d is the data dictionary 
url=d.url; 
url1=url[0] 
if (url1.substring(0, 4) == 'http') { 
    window.open(url); 
} 
""" 

taptool = p.select(type=TapTool) 
taptool.callback = CustomJS(args=dict(source=source1), code=jscode) 

#save file as .html 
with open("bokehRectangleLink.html","w") as f: 
    f.write(file_html(p, INLINE, "bokehRectangleLink")) 

#open the .html in the browser 
import webbrowser 
webbrowser.open("bokehRectangleLink.html")