[bokeh] How to clear all data in ColumnDataSource before updating it with periodic callback

Hi,

There is nothing built in to clear out all the existing columns of a data source, so for not you will just need to construct a new data dict with empty columns and set the .data of your CDS to that:

source.data = dict(x_time=[], x_only_time=[], ...)

If you have a list of these column names, then this might be easier:

source.data = { name : [] for name in colnames }

It might be nice to have a clear() method on CDS to do this automatically, please feel free to open a GH issue to discuss it.

Thanks,

Bryan

···

On Aug 2, 2017, at 11:31, Fatih Kılıç <[email protected]> wrote:

Hi everyone,

I have periodic callback function as I show below. I update ColumnDataSource using ".data" as it can be seen but I would like to clear all data in table_source ColumnDataSource before updating it. Could you please tell me how to clear all data in ColumnDataSource?

table_source = ColumnDataSource(dict(x_time=, x_only_time=, dev_ip=, iface=, bssid=, ssid=, ch=, con_sta=, i_a=, rx_b=, rx_p=, tx_b=, tx_p=, tx_r=, tx_f=, sig=, sig_a=, tx_bitrate=, rx_bitrate=, exp_th=, auth=, authen=, preamble=, wmm=, mfp=, tdls=, x_time_s=))

columns = [TableColumn(field="x_time", title="Date",formatter=DateFormatter(), width=85),
TableColumn(field="x_only_time", title="Time", width=85),
<CODE>
TableColumn(field="tdls", title="TDLS Peer", width=65),]
data_table = DataTable(source=table_source, columns=columns, width=1100, height=400, fit_columns=False, selectable=True)

# def sql_database
# def sql_database_plot

@count()
def update(t):
  
  x_time, x_only_time, dev_ip, iface, bssid, ssid, ch, con_sta, i_a, rx_b, rx_p, tx_b, tx_p, tx_r, tx_f, sig, sig_a, tx_bitrate, rx_bitrate, exp_th, auth, authen, preamble, wmm, mfp, tdls, x_time_s = sql_database(period)
  
  new_data = dict(x_time=[x_time], x_only_time=[x_only_time], dev_ip=[dev_ip], iface=[iface], bssid=[bssid], ssid=[ssid], ch=[ch], con_sta=[con_sta], i_a=[i_a], rx_b=[rx_b], rx_p=[rx_p], tx_b=[tx_b], tx_p=[tx_p], tx_r=[tx_r], tx_f=[tx_f], sig=[sig], sig_a=[sig_a], tx_bitrate=[tx_bitrate], rx_bitrate=[rx_bitrate], exp_th=[exp_th], auth=[auth], authen=[authen], preamble=[preamble], wmm=[wmm], mfp=[mfp], tdls=[tdls], x_time_s=[x_time_s])
  
  table_source.data = dict(x_time=x_time, x_only_time=x_only_time, dev_ip=dev_ip, iface=iface, bssid=bssid, ssid=ssid, ch=ch, con_sta=con_sta, i_a=i_a, rx_b=rx_b, rx_p=rx_p, tx_b=tx_b, tx_p=tx_p, tx_r=tx_r, tx_f=tx_f, sig=sig, sig_a=sig_a, tx_bitrate=tx_bitrate, rx_bitrate=rx_bitrate, exp_th=exp_th, auth=auth, authen=authen, preamble=preamble, wmm=wmm, mfp=mfp, tdls=tdls, x_time_s=x_time_s)

curdoc().add_periodic_callback(update, 500)

Thank you,

Regards,
Fatih

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/02c9a50e-7275-4407-859e-8ee4397062c3%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Does such a clear method exist meanwhile?
I couldn’t find it in the references, but better to ask before coding workarounds.

Since updating via source.data = empty_dict is no option for me (currently Arrows won’t update using it, see issue #9436), I use
source.stream=(empty_dict, rollover=-ro), where ro is the length of the columns.
I don’t think a negative rollover is intended to be used (maybe this needs also a fix) but for now it’s the only method that works for me to update the arrow sources to empty data.

@Matthias There is a clear method on the BokehJS side, but not the Python side. However, even if there were, it would just do something like:

self.data = { name : [] for name in colnames }

So it might not help for the Arrow case. I think that is just a bug to fix so that updates work as expected (regardless of how the update is made)