Best way to modify data source and trigger an update from the JS side?

I’m using the following, but you have to agree this is hacky. There’s got to be a better way to locate the data source object?

var source = Bokeh.index[Bokeh._.keys(Bokeh.index)[0]].model.document._roots[0].attributes.renderers[6].attributes.data_source

source.trigger(“change”);

Hi,

···

On Wed, Nov 30, 2016 at 10:25 AM, [email protected] wrote:

I’m using the following, but you have to agree this is hacky. There’s got to be a better way to locate the data source object?

var source = Bokeh.index[Bokeh._.keys(Bokeh.index)[0]].model.document._roots[0].attributes.renderers[6].attributes.data_source

source.trigger(“change”);

it would be useful to know the context in which you want to use this code, because it’s likely you can get the data source either directly or indirectly from the context, e.g. a custom js handler. Also, knowing how things were laid out would be helpful (is the top-level model a plot or a layout, etc.). Otherwise, the above line may be shortened to:

var source = Bokeh._.values(Bokeh.index)[0].model.renderers[6].data_source

or

var DataSource = require(“models/sources/data_source”).DataSource

var source = Bokeh._.values(Bokeh.index)[0].model.select_one(DataSource)

You can also select by name, etc. Don’t use attributes member directly as this is an internal implementation detail.

To modify a data source’s data, you can use either:

source.data = new_data;

or

source.data[“column_name”] = column

source.trigger(“change”)

Replacing entire data triggers change events automatically. It’s not possible with partial updates (in Python it’s possible with some magic).

Mateusz

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/f12d1397-f247-4a0c-a97e-e838e8e6cbd1%40continuum.io.

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

That’s hugely useful. The context is nil in my cases, as the update is initiated by the client side without custom js handler on the Python side. In another case the data is sourced from an ajax source on a click event, so I’m also finding the data source without a cb_obj.

I like the suggested way of finding the source, but

var DataSource = require(“models/sources/data_source”).DataSource

``

says

Module name “models/sources/data_source” has not been loaded yet for context: _.

``

What’s the best way to fix it?

···

On Wednesday, November 30, 2016 at 1:24:41 PM UTC, mateusz.paprocki wrote:

Hi,

On Wed, Nov 30, 2016 at 10:25 AM, [email protected] wrote:

I’m using the following, but you have to agree this is hacky. There’s got to be a better way to locate the data source object?

var source = Bokeh.index[Bokeh._.keys(Bokeh.index)[0]].model.document._roots[0].attributes.renderers[6].attributes.data_source

source.trigger(“change”);

it would be useful to know the context in which you want to use this code, because it’s likely you can get the data source either directly or indirectly from the context, e.g. a custom js handler. Also, knowing how things were laid out would be helpful (is the top-level model a plot or a layout, etc.). Otherwise, the above line may be shortened to:

var source = Bokeh._.values(Bokeh.index)[0].model.renderers[6].data_source

or

var DataSource = require(“models/sources/data_source”).DataSource

var source = Bokeh._.values(Bokeh.index)[0].model.select_one(DataSource)

You can also select by name, etc. Don’t use attributes member directly as this is an internal implementation detail.

To modify a data source’s data, you can use either:

source.data = new_data;

or

source.data[“column_name”] = column

source.trigger(“change”)

Replacing entire data triggers change events automatically. It’s not possible with partial updates (in Python it’s possible with some magic).

Mateusz

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/f12d1397-f247-4a0c-a97e-e838e8e6cbd1%40continuum.io.

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

Select by name works like magic, thank you!

···

On Wednesday, November 30, 2016 at 1:24:41 PM UTC, mateusz.paprocki wrote:

Hi,

On Wed, Nov 30, 2016 at 10:25 AM, [email protected] wrote:

I’m using the following, but you have to agree this is hacky. There’s got to be a better way to locate the data source object?

var source = Bokeh.index[Bokeh._.keys(Bokeh.index)[0]].model.document._roots[0].attributes.renderers[6].attributes.data_source

source.trigger(“change”);

it would be useful to know the context in which you want to use this code, because it’s likely you can get the data source either directly or indirectly from the context, e.g. a custom js handler. Also, knowing how things were laid out would be helpful (is the top-level model a plot or a layout, etc.). Otherwise, the above line may be shortened to:

var source = Bokeh._.values(Bokeh.index)[0].model.renderers[6].data_source

or

var DataSource = require(“models/sources/data_source”).DataSource

var source = Bokeh._.values(Bokeh.index)[0].model.select_one(DataSource)

You can also select by name, etc. Don’t use attributes member directly as this is an internal implementation detail.

To modify a data source’s data, you can use either:

source.data = new_data;

or

source.data[“column_name”] = column

source.trigger(“change”)

Replacing entire data triggers change events automatically. It’s not possible with partial updates (in Python it’s possible with some magic).

Mateusz

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/f12d1397-f247-4a0c-a97e-e838e8e6cbd1%40continuum.io.

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

Replacing entire data triggers change events automatically.
Doesn’t seem to work in bokeh 12.3. Replacing the whole data source, perhaps, not just the data property?

···

On Wednesday, November 30, 2016 at 1:24:41 PM UTC, mateusz.paprocki wrote:

Hi,

On Wed, Nov 30, 2016 at 10:25 AM, [email protected] wrote:

I’m using the following, but you have to agree this is hacky. There’s got to be a better way to locate the data source object?

var source = Bokeh.index[Bokeh._.keys(Bokeh.index)[0]].model.document._roots[0].attributes.renderers[6].attributes.data_source

source.trigger(“change”);

it would be useful to know the context in which you want to use this code, because it’s likely you can get the data source either directly or indirectly from the context, e.g. a custom js handler. Also, knowing how things were laid out would be helpful (is the top-level model a plot or a layout, etc.). Otherwise, the above line may be shortened to:

var source = Bokeh._.values(Bokeh.index)[0].model.renderers[6].data_source

or

var DataSource = require(“models/sources/data_source”).DataSource

var source = Bokeh._.values(Bokeh.index)[0].model.select_one(DataSource)

You can also select by name, etc. Don’t use attributes member directly as this is an internal implementation detail.

To modify a data source’s data, you can use either:

source.data = new_data;

or

source.data[“column_name”] = column

source.trigger(“change”)

Replacing entire data triggers change events automatically. It’s not possible with partial updates (in Python it’s possible with some magic).

Mateusz

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/f12d1397-f247-4a0c-a97e-e838e8e6cbd1%40continuum.io.

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

Hi,

···

On Wed, Nov 30, 2016 at 3:21 PM, [email protected] wrote:

That’s hugely useful. The context is nil in my cases, as the update is initiated by the client side without custom js handler on the Python side. In another case the data is sourced from an ajax source on a click event, so I’m also finding the data source without a cb_obj.

I like the suggested way of finding the source, but

var DataSource = require(“models/sources/data_source”).DataSource

``

says

Module name “models/sources/data_source” has not been loaded yet for context: _.

``

What’s the best way to fix it?

I think you have to use Bokeh.require("…") instead. I was a bit presumptuous about require() pointing to bokeh, but likely is something different (node or whatever bundler you use).

Mateusz

On Wednesday, November 30, 2016 at 1:24:41 PM UTC, mateusz.paprocki wrote:

Hi,

On Wed, Nov 30, 2016 at 10:25 AM, [email protected] wrote:

I’m using the following, but you have to agree this is hacky. There’s got to be a better way to locate the data source object?

var source = Bokeh.index[Bokeh._.keys(Bokeh.index)[0]].model.document._roots[0].attributes.renderers[6].attributes.data_source

source.trigger(“change”);

it would be useful to know the context in which you want to use this code, because it’s likely you can get the data source either directly or indirectly from the context, e.g. a custom js handler. Also, knowing how things were laid out would be helpful (is the top-level model a plot or a layout, etc.). Otherwise, the above line may be shortened to:

var source = Bokeh._.values(Bokeh.index)[0].model.renderers[6].data_source

or

var DataSource = require(“models/sources/data_source”).DataSource

var source = Bokeh._.values(Bokeh.index)[0].model.select_one(DataSource)

You can also select by name, etc. Don’t use attributes member directly as this is an internal implementation detail.

To modify a data source’s data, you can use either:

source.data = new_data;

or

source.data[“column_name”] = column

source.trigger(“change”)

Replacing entire data triggers change events automatically. It’s not possible with partial updates (in Python it’s possible with some magic).

Mateusz

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/f12d1397-f247-4a0c-a97e-e838e8e6cbd1%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/63357bb4-9e66-456b-99df-a0f8a05350f5%40continuum.io.

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