如何从小部件调用的函数中更新bokeh downloadbutton的源



如何更新Bokeh下载按钮的来源?在我的例子中,当调用其他小部件时,我调用update((。update((函数也是我更新"df_updated"数据帧的地方,该数据帧需要下载,但只有在单击下载按钮时才能下载。如有任何帮助,我们将不胜感激。

def update()
# some process...
df_updated = <whatever>
downloadbutton.js_on_click(CustomJS(args=dict(source=source),
code=open(join(dirname(__file__), "download.js")).read()))
myselect.on_click(update)

我试过这样的东西,但它没有更新下载按钮的来源:

dl_source = something # initialize
def update()
global dl_source
# some process...
df_updated = <whatever>
dl_source = ColumnDataSource(df_updated)
downloadbutton.js_on_click(CustomJS(args=dict(source=dl_source),
code=open(join(dirname(__file__), "download.js")).read()))
myselect.on_click(update)

终于找到了办法。在更新数据帧的函数中,我们需要使用source.data=而不是source=

以下是它的外观:

df=pd.DataFrame()
source = ColumnDataSource(df) # initialize to whatever u want
def update()
# some process...
df_updated = <whatever>
cds = ColumnDataSource(df_updated)
source.data = dict(cds.data)  # this is what was the difference in the end
downloadbutton.js_on_click(CustomJS(args=dict(source=source),
code=open(join(dirname(__file__), "download.js")).read()))
myselect.on_click(update) # call update() to update the df

最新更新