How to subclass ColumnDataSource

Hi,

I want to subclass ColumnDataSource. However, when trying to use this source for plotting (in a jupyter notebook), I get

Javascript error adding output!

Error:
Model `NbColumnDataSource’ does not exist. This could be due to a widget or a custom model not being registered before first usage.

See your browser Javascript console for more details.

The subclass definition is as simple as possible (for now),

class NbColumnDataSource(bokeh.models.ColumnDataSource):

pass

Is there a trick to subclassing? When looking at the source code for the source included in bokeh I colud not see one…

Best,
Lukas

Hi,

···

On Mon, Apr 10, 2017 at 11:00 AM, [email protected] wrote:

Hi,

I want to subclass ColumnDataSource. However, when trying to use this source for plotting (in a jupyter notebook), I get

Javascript error adding output!

Error:
Model `NbColumnDataSource’ does not exist. This could be due to a widget or a custom model not being registered before first usage.

See your browser Javascript console for more details.

The subclass definition is as simple as possible (for now),

class NbColumnDataSource(bokeh.models.ColumnDataSource):

pass

Is there a trick to subclassing? When looking at the source code for the source included in bokeh I colud not see one…

every model in bokeh has to have a corresponding model implementation in bokehjs. You can override this behavior by implementing NbColumnDataSource as:

class NbColumnDataSource(bokeh.models.ColumnDataSource):

subtype = “NbColumnDataSource”

view_model = “ColumnDataSource”

This is how e.g. Figure model is implemented (see bokeh.plotting.figure). I’m pretty sure you won’t be able to add new properties to a model if it’s implemented like this.

Mateusz

Best,
Lukas

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/a3a230d8-f565-4992-9ce2-caa0dfdd9caa%40continuum.io.

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

Lukas,

Can you elaborate on what you are trying to accomplish? If you want new BokehJS behaviour, then you'd provide a JS implementation as described in:

  http://bokeh.pydata.org/en/0.12.5/docs/user_guide/extensions.html

but then you would not need the technique Mateusz mentions with "__subtype__". That technique is useful when you want to re-use a BokehJS implementation but want to add some new capability to the python side model only. I don't see what could ever be useful about a model subclass that just has "pass" as the entire body.

Thanks,

Bryan

···

On Apr 10, 2017, at 09:12, Mateusz Paprocki <[email protected]> wrote:

Hi,

On Mon, Apr 10, 2017 at 11:00 AM, <[email protected]> wrote:
Hi,

I want to subclass ColumnDataSource. However, when trying to use this source for plotting (in a jupyter notebook), I get

Javascript error adding output!
Error: Model `NbColumnDataSource' does not exist. This could be due to a widget or a custom model not being registered before first usage.
See your browser Javascript console for more details.

The subclass definition is as simple as possible (for now),

class NbColumnDataSource(bokeh.models.ColumnDataSource):
pass

Is there a trick to subclassing? When looking at the source code for the source included in bokeh I colud not see one…

every model in bokeh has to have a corresponding model implementation in bokehjs. You can override this behavior by implementing NbColumnDataSource as:

class NbColumnDataSource(bokeh.models.ColumnDataSource):
    __subtype__ = "NbColumnDataSource"
    __view_model__ = "ColumnDataSource"

   ...

This is how e.g. Figure model is implemented (see bokeh.plotting.figure). I'm pretty sure you won't be able to add new properties to a model if it's implemented like this.

Mateusz

Best,
Lukas

--
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/a3a230d8-f565-4992-9ce2-caa0dfdd9caa%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/CANFzp8guzaMXNdap%2BXjrdaz-JDVRN_Aq_%2BiK8ekdBQJ3pyYEJw%40mail.gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

Lukas,

Can you elaborate on what you are trying to accomplish?

I just wanted to modify init to call a custom function but otherwise the class should behave exactly like ColumnDataSource. Mateusz’ solution works perfectly for that.

Thanks a lot,
Lukas

···

Am Montag, 10. April 2017 16:19:31 UTC+2 schrieb Bryan Van de ven:

If you want new BokehJS behaviour, then you’d provide a JS implementation as described in:

    [http://bokeh.pydata.org/en/0.12.5/docs/user_guide/extensions.html](http://bokeh.pydata.org/en/0.12.5/docs/user_guide/extensions.html)

but then you would not need the technique Mateusz mentions with “subtype”. That technique is useful when you want to re-use a BokehJS implementation but want to add some new capability to the python side model only. I don’t see what could ever be useful about a model subclass that just has “pass” as the entire body.

Thanks,

Bryan

On Apr 10, 2017, at 09:12, Mateusz Paprocki [email protected] wrote:

Hi,

On Mon, Apr 10, 2017 at 11:00 AM, [email protected] wrote:

Hi,

I want to subclass ColumnDataSource. However, when trying to use this source for plotting (in a jupyter notebook), I get

Javascript error adding output!

Error: Model `NbColumnDataSource’ does not exist. This could be due to a widget or a custom model not being registered before first usage.

See your browser Javascript console for more details.

The subclass definition is as simple as possible (for now),

class NbColumnDataSource(bokeh.models.ColumnDataSource):

pass

Is there a trick to subclassing? When looking at the source code for the source included in bokeh I colud not see one…

every model in bokeh has to have a corresponding model implementation in bokehjs. You can override this behavior by implementing NbColumnDataSource as:

class NbColumnDataSource(bokeh.models.ColumnDataSource):

__subtype__ = "NbColumnDataSource"
__view_model__ = "ColumnDataSource"

This is how e.g. Figure model is implemented (see bokeh.plotting.figure). I’m pretty sure you won’t be able to add new properties to a model if it’s implemented like this.

Mateusz

Best,

Lukas


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/a3a230d8-f565-4992-9ce2-caa0dfdd9caa%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/CANFzp8guzaMXNdap%2BXjrdaz-JDVRN_Aq_%2BiK8ekdBQJ3pyYEJw%40mail.gmail.com.

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

Hi,

Hi,

Hi,

I want to subclass ColumnDataSource. However, when trying to use this source for plotting (in a jupyter notebook), I get

Javascript error adding output!

Error:
Model `NbColumnDataSource’ does not exist. This could be due to a widget or a custom model not being registered before first usage.

See your browser Javascript console for more details.

The subclass definition is as simple as possible (for now),

class NbColumnDataSource(bokeh.models.ColumnDataSource):

pass

Is there a trick to subclassing? When looking at the source code for the source included in bokeh I colud not see one…

every model in bokeh has to have a corresponding model implementation in bokehjs. You can override this behavior by implementing NbColumnDataSource as:

class NbColumnDataSource(bokeh.models.ColumnDataSource):

subtype = “NbColumnDataSource”

view_model = “ColumnDataSource”

This is how e.g. Figure model is implemented (see bokeh.plotting.figure). I’m pretty sure you won’t be able to add new properties to a model if it’s implemented like this.

That’s all I need. It works perfectly. Thank you very much!

Lukas

···

Am Montag, 10. April 2017 16:12:47 UTC+2 schrieb mateusz.paprocki:

On Mon, Apr 10, 2017 at 11:00 AM, [email protected] wrote:

Mateusz

Best,
Lukas

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/a3a230d8-f565-4992-9ce2-caa0dfdd9caa%40continuum.io.

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