Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] DataTable autosize_mode = "fit_viewport" does not adjust column widths as data is updated #11746

Open
EfremBraun opened this issue Oct 15, 2021 · 0 comments
Labels

Comments

@EfremBraun
Copy link
Contributor

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

Bokeh 2.4.1
Python 3.9.6
MacOS Catalina 10.15.7
Chrome 94.0.4606.81

Description of expected behavior and the observed behavior

When using DataTable's autosize_mode = "fit_viewport", the columns don't get updated when the data or headers change. In applications where the table begins empty and gets filled when the user selects options, this can result in the data looking squished.

That is unlike when using DataTable's autosize_mode = "fit_columns", which updates the column sizes dynamically and is quite nice.

This issue is likely related to #11436.

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

Take https://github.com/bokeh/bokeh/tree/branch-3.0/examples/app/export_csv and updated main.py to:

from os.path import dirname, join

import pandas as pd

from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import (Button, ColumnDataSource, CustomJS, DataTable,
                          NumberFormatter, RangeSlider, TableColumn)

df = pd.read_csv(join(dirname(__file__), 'salary_data.csv'))

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, 10000), step=1000, format="0,0")
slider.on_change('value', lambda attr, old, new: update())

button = Button(label="Download", button_type="success")
button.js_on_click(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, autosize_mode='fit_columns')
data_table = DataTable(source=source, columns=columns, width=800, autosize_mode='fit_viewport')

controls = column(slider, button)

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

update()

When the sliders get adjusted such that data appears in the table, the column widths don't get updated.
If you change the DataTable to autosize_mode='fit_columns', the columns width do get updated.

Screenshots or screencasts of the bug in action

Squished columns:
Screen Shot 2021-10-15 at 3 04 13 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant