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

Race condition causes sorters to be reset if set after updating data #2638

Closed
philippjfr opened this issue Aug 17, 2021 · 0 comments · Fixed by #2639
Closed

Race condition causes sorters to be reset if set after updating data #2638

philippjfr opened this issue Aug 17, 2021 · 0 comments · Fixed by #2639
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@philippjfr
Copy link
Member

When pagination is disabled the request that fetches new pages gets triggered when setting new data. This request also sends the sorters, which are reset to empty after the data is updated. Therefore the sorters are reset after updating the data:

import pandas as pd
import panel as pn

df1 = pd.DataFrame({
    'A': [1, 2, 3],
    'B': [4, 5, 6],
})

df2 = pd.DataFrame({
    'A': [10, 20, 30],
    'B': [40, 50, 60],
})

dfs = {
    'df1': df1,
    'df2': df2.iloc[:1],
}

sorters = {'df1': [], 'df2': []}

def sorting_callback(event):
    print('sorting_callback', event)
    sorters[dropdown.value] = event.new
    print('sorters', sorters)

table = pn.widgets.Tabulator(
    value=None,
    pagination='remote',
    page_size=2
)

def dropdown_callback(event):
    print('dropdown_callback', event)
    new_table = event.new
    print('sorters', sorters)
    table.value = dfs[new_table]
    table.sorters = sorters[new_table]

table.param.watch(sorting_callback, 'sorters')

options = list(dfs.keys())
dropdown = pn.widgets.Select(
    options=options, width=200,
)
dropdown.param.watch(dropdown_callback, 'value', onlychanged=False)
dropdown.value = options[0]

tmpl = pn.template.MaterialTemplate()
tmpl.main.append(dropdown)
tmpl.main.append(table)
tmpl.servable()
@philippjfr philippjfr added the TRIAGE Default label for untriaged issues label Aug 17, 2021
@philippjfr philippjfr added this to the 0.12.2 milestone Aug 17, 2021
@philippjfr philippjfr added type: bug Something isn't correct or isn't working and removed TRIAGE Default label for untriaged issues labels Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant