【问题标题】:Bokeh TableData on_change selected event called twiceBokeh TableData on_change 选择的事件调用了两次
【发布时间】:2016-11-08 08:17:49
【问题描述】:

我有一个带有 Select、DataTable 和 Button 的 Bokeh UI。

  • 选择允许直接转到数据表中的给定行
  • 按钮允许转到 DataTable 中的下一行
  • DataTable 允许直接选择单行(因此更新 Select)。

DataTable 通过以下方式跟踪选择更改事件:

self.__table_data.on_change('selected',self.table_selection_change)

单击按钮时,我将 DataTable 源的 selected 属性更改为新的 dict 结构,如 here 所示:

self.__table_data.selected = {'2d': {'indices': []}, '1d': {'indices': [my_new_index]}, '0d': {'indices': [], 'glyph': None}}

问题是,当我进行此更新时,我的回调 (table_selection_change) 被调用了两次,而我预计只有一次调用。

【问题讨论】:

    标签: python datatable event-handling bokeh


    【解决方案1】:

    问题是整个字典不应该被更新。只有相关的键必须更新。

    替换

    self.__table_data.selected = {'2d': {'indices': []}, '1d': {'indices': [my_new_index]}, '0d': {'indices': [], 'glyph': None}}
    

    通过

    self.__table_data.selected['1d'] = {'indices':[my_new_index]}
    

    解决问题。

    【讨论】:

      猜你喜欢
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 2011-10-07
      • 2022-08-20
      • 1970-01-01
      相关资源
      最近更新 更多