通过CustomJS将变量从bokeh传递到JS [英] Pass variables from bokeh to JS via CustomJS

查看:208
本文介绍了通过CustomJS将变量从bokeh传递到JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bokeh示例中 http ://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-hover 通过在代码块的末尾添加字典,将字典"links"传递给JS: ....

In the bokeh example http://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-hover the dictonary "links" is passed to the JS by adding it at the end of the code block with: ....

""" % links

是否可以传递两个变量,语法是什么样的? 我尝试过类似的版本

Is it possible to pass over two variables and what would the syntax look like? I tried different versions like

""" % links,myvar
""" % ('links','myvar')
""" % links, % myvar

,但是它们全都产生错误或不起作用. 我也发现了这个 Bokeh:将vars传递给CustomJS for Widgets 但也许有更新? 谢谢

but they all create errors or do not work. I also found this Bokeh: pass vars to CustomJS for Widgets but perhaps there is an update? Thx

推荐答案

我建议您研究一般的python字符串格式(该示例中没有特定于Bokeh的内容).

I'd suggest looking into general python string formatting (there isn't anything Bokeh-specific within that example).

但是有些选择会

JS_CODE = """
var variable_1 = %s
var variable_2 = %s
""" % (var1, var2)

JS_CODE = """
var variable_1 = {0}
var variable_2 = {1}
""".format(var1, var2)

或设置为列表

JS_CODE = """
var list_variable = %s
""".format(str(list_var))

docs: https://docs.python.org/2/library/string.html#formatexamples

这篇关于通过CustomJS将变量从bokeh传递到JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆