Chart on click selection from data table in Bokeh

后端 未结 2 1634
攒了一身酷
攒了一身酷 2021-01-24 06:26

I\'ve taken the below code from another source - it is not my own code.

The code allows you to select a cell in the data table, and the \'downloads\' data for that cell

2条回答
  •  温柔的废话
    2021-01-24 07:19

    My suggestion is to use my another post that uses a JS callback to access the row and column of the selected cell. This must be a JS callback as it uses HTML elements to walk through. So the steps are as follows:

    1. Define a new ColumnDataSource that will contain the row and column number of a clicked cell

      info_source = ColumnDataSource(dict(row = [], column = []))

    2. Use the JS callback from this post to fill in the row and column values in this new table_info_source like this:

    callback=CustomJS(args=dict(source=d_source,source2=info_source),code=source_code)
    source.selected.js_on_change('indices', callback)

    1. Inside the JS callback store the row and column index like this:

      source2.data = {row:[row],column:[column]};

    2. Access the info_source.data information in your Python callback to draw a plot

      print (info_source.data)

    Both callback are attached to the same source but usually JS callback is executed first so the data should be available in the Python callback on time. Having the index of row and column of the clicked cell you should be able to retrieve the required data and draw your chart.

提交回复
热议问题