Pass variables from bokeh to JS via CustomJS

蓝咒 提交于 2020-01-14 05:14:49

问题


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

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


回答1:


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

But some options would be

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

or

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

or to set as a list

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

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



来源:https://stackoverflow.com/questions/40158529/pass-variables-from-bokeh-to-js-via-customjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!