在散景示例中http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#customjs-for-hover
dictonary“links
”通过在代码块的末尾添加它来传递给JS:
....
""" % links
是否可以传递两个变量,语法是什么样的? 我尝试了不同的版本,如
""" % links,myvar
""" % ('links','myvar')
""" % links, % myvar
但它们都会产生错误或无法正常工作。 我也找到了这个 Bokeh: pass vars to CustomJS for Widgets 但也许有更新? THX
答案 0 :(得分:3)
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