I’m seeing strange behavior with my DataTable.
I more or less copied the bokeh example code from here:
https://demo.bokehplots.com/apps/export_csv
Problem is, when I adjust the textbox or slider it doesn’t “completely” update the data frame. Not all of the filtering takes place properly. It’s like it doesn’t get done with the update work before trying to show it to the screen.
Thinking it might be some sort of timing thing, I changed the code to call update twice upon sensing any events. After update gets called twice it works fine. I can even see the first iteration look wrong and then immediately get updated with the right update.
Make sense?
Pseudo code is below, along with the change that made it “work”. Any ideas what I’m doing wrong? I’d prefer not to call update twice if I could.
Note – not sure if this is standard, but I have four sliders, two checkboxcgroup and a textinput. So lots of things that are possible to update.
pseudo code:
df = read.csv(“blah”) #read in data frame
source = ColumnDataSource(data=dict()) #set up empty source
def update():
current = some slice of the df
update source.dict with the data in current
set up TextInput
set up slider 1
set up slider 2
set up slider 3
set up slider 4
set up CheckBoxGroup1
set up CheckBoxGroup2
set up columns for data table
data_table = DataTable(source=source, columns=columns, width=800, scroll_to_selection = False, sortable = True)
controls = widgetbox(the_textbox,
a1_slider,
a2_slider,
a3_slider,
a4_slider,
a1_checkboxgroup,
a2_ckeckboxgroup,
)
table = widgetbox(data_table)
the_textbox.on_change(‘value’, lambda attr, old, new: update())
a1_slider.on_change(‘value’, lambda attr, old, new: update())
a2_slider.on_change(‘value’, lambda attr, old, new: update())
a3_slider.on_change(‘value’, lambda attr, old, new: update())
a4_slider.on_change(‘value’, lambda attr, old, new: update())
a1_checkboxgroup.on_change(‘active’, lambda attr, old, new: update())
a2_checkboxgroup.on_change(‘active’,lambda attr, old, new: update())
update()
<details class='elided'>
<summary title='Show trimmed content'>···</summary>
------------
fix included creating a function called updatetwice and then calling updatetwice() whenever a chance is noticed.
def updatetwice():
update()
update()
a1_slider.on_change(‘value’, lambda attr, old, new: updatetwice()) # did this for all sliders, checkboxgroups and textbox
voila – it works now. curious.
</details>