Can callback on 1 widget apply to another widget?

Hello,

I can not manage to update a select widget options with an other widget slider for example.

If I have a table with ‘x’ and ‘value’ columns, a slider widget for ‘x’ and a select widget for 'value, and if I want to filter table with ‘x’ higher than 10 for example, the datatable will be updated and also the plot if any, but not the select widget. It will keep alll possible values in its options.

Maybe it is impossible to do it.

Can someone confirm?

Thanks.

David

It’s definitely possible to e.g. update one select widget’s values based on another select widget’s choice. But I’m on a phone and don’t have code handy. Maybe you can share some code of what you’ve tried that hasn’t worked. It’s always advised to share code when asking for help.

Thanks,

Bryan

···

On Nov 20, 2016, at 09:11, [email protected] wrote:

Hello,

I can not manage to update a select widget options with an other widget slider for example.

If I have a table with ‘x’ and ‘value’ columns, a slider widget for ‘x’ and a select widget for 'value, and if I want to filter table with ‘x’ higher than 10 for example, the datatable will be updated and also the plot if any, but not the select widget. It will keep alll possible values in its options.

Maybe it is impossible to do it.

Can someone confirm?

Thanks.

David

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/793620e7-ae18-48fc-8bb9-28cd093c5481%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Here is the code:

df = pd.read_csv(“foo.csv”)

source = ColumnDataSource(df)
original_source = ColumnDataSource(df)
columns = [
TableColumn(field=“x”, title=“x”, width=20),
TableColumn(field=“y”, title=“y”, width=20),
TableColumn(field=“Try”, title=“Try”, width=10),
TableColumn(field=“N”, title=“N”, width=60),
]
data_table = DataTable(source=source, columns=columns, height=700, row_headers=False)

callback code to be used by all the filter widgets

combined_callback_code = “”"
var data = source.get(‘data’);
var original_data = original_source.get(‘data’);
var Try = Try_select_obj.get(‘value’);
var n = n_select_obj.get(‘value’);
var x = x_slide_obj.get(‘value’);

for (var key in original_data) {
data[key] = ;
for (var i = 0; i < original_data[‘Try’].length; ++i) {
if ((Try === “ALL” || original_data[‘Try’][i] === parseInt(Try,10)) &&
(n === “ALL” || original_data[‘N’][i] === n) &&
(original_data[‘x’][i] >= x) {
data[key].push(original_data[key][i]);
}
}
}

target_obj.trigger(‘change’);
source.trigger(‘change’);
Try_list.trigger(‘change’);
n_list.trigger(‘change’);
n_select.trigger(‘change’);
console.log(“source updated " );
“””

define the filter widgets, without callbacks for now

Try_list = [‘ALL’] + sorted(set([str(z) for z in source.data[‘Try’]]))
Try_select = Select(title=“Try:”,options=Try_list, value=Try_list[0], width=200)

n_list = [‘ALL’] + sorted(set((source.data[‘N’])))
n_select = Select(title=“N: (expected: 024C4E12)”, value=n_list[0], options=n_list, width=200)

x_slide = Slider(start=0, end=1500, value=0, step=1, title=“x”, width=200)

now define the callback objects now that the filter widgets exist

common_callback = CustomJS(
args=dict(source=source,
original_source=original_source,
Try_select_obj=Try_select,
n_select_obj=n_select,
x_slide_obj=x_slide,
target_obj=data_table),
code=combined_callback_code)

finally, connect the callbacks to the filter widgets

Try_select.callback = common_callback
n_select.callback = common_callback
x_slide.callback = common_callback

TOOLS=“hover,crosshair,pan,wheel_zoom,box_zoom,undo,redo,reset,tap,save,box_select,poly_select,lasso_select”
plot = figure(x_range=(0,1500),y_range=(0,1500),tools=TOOLS, width=800, height=800)
plot.min_border_right = 50
plot.image_url(url=[‘foo.jpg’], x=-22, y=-72,w=1476,h=1033,anchor=‘bottom_left’, alpha=0.7, angle=-0.0)
plot.circle(‘x’,‘y’, source=source, size=3, color=‘yellow’)

output_file(“Centaurus1.html”, mode=‘inline’, title=“Centaurus 1 laser attacks”)

layout=row(plot,column(x_slide,Try_select, n_select, sizing_mode=‘fixed’, width=250), data_table)
show(layout)

``

So for example when x_slide is modified I would like that n_list and Try_list update automatically.
I thought it was done through source.trigger(‘change’).

David

···

Le dimanche 20 novembre 2016 17:44:59 UTC+1, Bryan Van de ven a écrit :

It’s definitely possible to e.g. update one select widget’s values based on another select widget’s choice. But I’m on a phone and don’t have code handy. Maybe you can share some code of what you’ve tried that hasn’t worked. It’s always advised to share code when asking for help.

Thanks,

Bryan

On Nov 20, 2016, at 09:11, [email protected] wrote:

Hello,

I can not manage to update a select widget options with an other widget slider for example.

If I have a table with ‘x’ and ‘value’ columns, a slider widget for ‘x’ and a select widget for 'value, and if I want to filter table with ‘x’ higher than 10 for example, the datatable will be updated and also the plot if any, but not the select widget. It will keep alll possible values in its options.

Maybe it is impossible to do it.

Can someone confirm?

Thanks.

David

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/793620e7-ae18-48fc-8bb9-28cd093c5481%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

The contents of the select widgets is controlled solely by the value of the .options property on the widget object. I don't see that you are updating e.g., n_select_obj.options to anything new anywhere, so I would not expect the selection options to change. If you want the widgets options to change, you need to set widget.options to a new value (some new list of strings to display).

FYI in recent releases it is no longer necessary (and is in fact deprecated) to use cumbersome "obj.get('foo')" syntax anymore, just use the much simpler "obj.foo" syntax going forward.

Thanks,

Bryan

···

On Nov 21, 2016, at 2:53 AM, [email protected] wrote:

Here is the code:

df = pd.read_csv("foo.csv")

source = ColumnDataSource(df)
original_source = ColumnDataSource(df)
columns = [
    TableColumn(field="x", title="x", width=20),
    TableColumn(field="y", title="y", width=20),
    TableColumn(field="Try", title="Try", width=10),
    TableColumn(field="N", title="N", width=60),
]
data_table = DataTable(source=source, columns=columns, height=700, row_headers=False)

# callback code to be used by all the filter widgets
combined_callback_code = """
var data = source.get('data');
var original_data = original_source.get('data');
var Try = Try_select_obj.get('value');
var n = n_select_obj.get('value');
var x = x_slide_obj.get('value');

for (var key in original_data) {
    data[key] = ;
    for (var i = 0; i < original_data['Try'].length; ++i) {
        if ((Try === "ALL" || original_data['Try'][i] === parseInt(Try,10)) &&
        (n === "ALL" || original_data['N'][i] === n) &&
        (original_data['x'][i] >= x) {
            data[key].push(original_data[key][i]);
        }
    }
}

target_obj.trigger('change');
source.trigger('change');
Try_list.trigger('change');
n_list.trigger('change');
n_select.trigger('change');
console.log("source updated " );
"""

# define the filter widgets, without callbacks for now

Try_list = ['ALL'] + sorted(set([str(z) for z in source.data['Try']]))
Try_select = Select(title="Try:",options=Try_list, value=Try_list[0], width=200)

n_list = ['ALL'] + sorted(set((source.data['N'])))
n_select = Select(title="N: (expected: 024C4E12)", value=n_list[0], options=n_list, width=200)

x_slide = Slider(start=0, end=1500, value=0, step=1, title="x", width=200)

# now define the callback objects now that the filter widgets exist
common_callback = CustomJS(
    args=dict(source=source,
              original_source=original_source,
              Try_select_obj=Try_select,
              n_select_obj=n_select,
              x_slide_obj=x_slide,
              target_obj=data_table),
    code=combined_callback_code)

# finally, connect the callbacks to the filter widgets
Try_select.callback = common_callback
n_select.callback = common_callback
x_slide.callback = common_callback

TOOLS="hover,crosshair,pan,wheel_zoom,box_zoom,undo,redo,reset,tap,save,box_select,poly_select,lasso_select"
plot = figure(x_range=(0,1500),y_range=(0,1500),tools=TOOLS, width=800, height=800)
plot.min_border_right = 50
plot.image_url(url=['foo.jpg'], x=-22, y=-72,w=1476,h=1033,anchor='bottom_left', alpha=0.7, angle=-0.0)
plot.circle('x','y', source=source, size=3, color='yellow')

output_file("Centaurus1.html", mode='inline', title="Centaurus 1 laser attacks")

layout=row(plot,column(x_slide,Try_select, n_select, sizing_mode='fixed', width=250), data_table)
show(layout)

So for example when x_slide is modified I would like that n_list and Try_list update automatically.
I thought it was done through source.trigger('change').

David

Le dimanche 20 novembre 2016 17:44:59 UTC+1, Bryan Van de ven a écrit :
It's definitely possible to e.g. update one select widget's values based on another select widget's choice. But I'm on a phone and don't have code handy. Maybe you can share some code of what you've tried that hasn't worked. It's always advised to share code when asking for help.

Thanks,

Bryan

On Nov 20, 2016, at 09:11, [email protected] wrote:

Hello,
I can not manage to update a select widget options with an other widget slider for example.
If I have a table with 'x' and 'value' columns, a slider widget for 'x' and a select widget for 'value, and if I want to filter table with 'x' higher than 10 for example, the datatable will be updated and also the plot if any, but not the select widget. It will keep alll possible values in its options.
Maybe it is impossible to do it.
Can someone confirm?
Thanks.
David

--
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/793620e7-ae18-48fc-8bb9-28cd093c5481%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
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/0d6f956b-fcba-40f7-bba4-9ec6e704ff4c%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Understood.
Thanks a lot.
It works.
David

···

Le dimanche 20 novembre 2016 16:33:28 UTC+1, [email protected] a écrit :

Hello,

I can not manage to update a select widget options with an other widget slider for example.

If I have a table with ‘x’ and ‘value’ columns, a slider widget for ‘x’ and a select widget for 'value, and if I want to filter table with ‘x’ higher than 10 for example, the datatable will be updated and also the plot if any, but not the select widget. It will keep alll possible values in its options.

Maybe it is impossible to do it.

Can someone confirm?

Thanks.

David