Skip to content

DataTable does not stay sorted when the data is updated #8201

Closed

Description

@lesteve

ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

bokeh: 0.13.0
python: 3.6.5
OS: Ubuntu 16.04
Browser: Firefox and Chromium

Description of expected behavior and the observed behavior

This is based on the example at https://demo.bokehplots.com/apps/export_csv. Click on the "Experience" column to sort by Experience. Then move the slider on the left hande side that defines the salary range.

  • actual behavior: the data is not sorted anymore by Experience
  • expected behavior: the table stays sorted by Experience when you move the slider

Complete, minimal, self-contained example code that reproduces the issue

This is a copy of paste of the example at https://demo.bokehplots.com/apps/export_csv except with 10 data points.

from os.path import dirname, join

import pandas as pd

from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.widgets import RangeSlider, Button, DataTable, TableColumn, NumberFormatter
from bokeh.io import curdoc

df = pd.read_csv(join(dirname(__file__), 'salary_data.csv')).iloc[:10]

source = ColumnDataSource(data=dict())

def update():
    current = df[(df['salary'] >= slider.value[0]) & (df['salary'] <= slider.value[1])].dropna()
    source.data = {
        'name'             : current.name,
        'salary'           : current.salary,
        'years_experience' : current.years_experience,
    }

slider = RangeSlider(title="Max Salary", start=10000, end=110000, value=(10000, 50000), step=1000, format="0,0")
slider.on_change('value', lambda attr, old, new: update())

button = Button(label="Download", button_type="success")
button.callback = CustomJS(args=dict(source=source),
                           code=open(join(dirname(__file__), "download.js")).read())

columns = [
    TableColumn(field="name", title="Employee Name"),
    TableColumn(field="salary", title="Income", formatter=NumberFormatter(format="$0,0.00")),
    TableColumn(field="years_experience", title="Experience (years)")
]

data_table = DataTable(source=source, columns=columns, width=800)

controls = widgetbox(slider, button)
table = widgetbox(data_table)

curdoc().add_root(row(controls, table))
curdoc().title = "Export CSV"

update()

Side-comment: I noticed that in a dask context, I wanted the workers sorted by CPU usage (similar to htop) in the dask dashboard but the sorting disappears on the first data update.

Activity

  1. added this to the milestone on Sep 1, 2018
  2. lesteve commented on Sep 1, 2018

    @lesteve
    Author

    Here is a gif: bokeh

  3. modified the milestones: , 1.0 on Oct 11, 2018
  4. github-actions commented on Oct 27, 2024

    @github-actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  5. locked as resolved and limited conversation to collaborators on Oct 27, 2024
  6. added theissue type on Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions