Hi Mateusz, Thanks so much for catching those errors. There is one
final piece that is not working with the custom model, that is the
backbone template on line 15 of custom.js. I tried both of these
Hi,
On Mon, Dec 5, 2016 at 6:10 PM, Alex Rice <[email protected]> wrote:
Hi all,
I am still unable to create a custom model with javascript code. Here
is exactly what i am doing, and how it is failing. Aside: can anyone
share an example of a bokeh custom model implemented with javascript
code, which also works with the latest -dev release?
1) installed latest dev release per Mateusz advice:
$ conda list bokeh
# packages in environment at /Users/agr/miniconda3/envs/cmap2:
bokeh 0.12.4dev6 py_1
bokeh/channel/dev
2) Used current example code suggested by Mateusz and I also confirmed
this coffeescript model works fine for me in my environment:
https://github.com/bokeh/bokeh/blob/master/sphinx/source/docs/user_guide/examples/extensions_putting_together.py
3) Hand-converted the coffee-script to javascript (I suspect I could
have made an error here as I don't know coffeescript very well yet).
Here is the python and javascript code I am using now
https://gist.github.com/guidorice/ee9ec2f5bd3a67e504bf9b564c533871
This translation has several errors, most notably static initialization of
Custom class is wrong. I suggest going back to decaffeinate, as it did good
job translating CoffeeScript. Previously any errors were due to using older
code as the basis, so it should work fine now (should, because decaffeinate
has some issues, but hopefully you're not going to hit them). This is
how Custom class should look like:
export class Custom extends LayoutDOM {}
Custom.prototype.default_view = CustomView;
Custom.prototype.type = "Custom";
Custom.define({
text: [ p.String ],
slider: [ p.Any ]
});
Note that this may be implemented differently, but there is no direct
syntactic equivalent (as far as I know).
Now Bokeh builds with no errors or warnings, but just fails at
runtime. Here is the Bokeh runtime error, in my browser, when I run
"python custom_app.py "
> Model `Custom' does not exists. The problem may be two fold. Either a
> model was requested that's available in an extra bundle, e.g. a widget, or a
> custom model was requested, but it wasn't registered before first usage.
This is because of this line:
__implementation__ = JavaScript('custom.js')
It should be changed to:
__implementation__ = FromFile('custom.js')
JavaScript() is meant to indicate that inline code is JavaScript, as we
otherwise can't deduce that. With external code, extensions are used to
determine the language.
Mateusz
Thanks for any assistance you can provide!
Alex Rice // National Center for Genome Resources <[email protected]>
On Thu, Dec 1, 2016 at 11:53 AM, Mateusz Paprocki >>>> <[email protected]> wrote:
> Hi,
>
> On Wed, Nov 30, 2016 at 8:15 PM, Alex Rice <[email protected]> wrote:
>>
>> Hi Mateusz,
>>
>> As you suggest, changing the implementation of Custom class to:
>>
>> from bokeh.util.compiler import JavaScript
>> ...
>> __implementation__ = JavaScript('custom.js')
>>
>> it now compiles, where it was erring before. So that is solved. But it
>> fails at runtime, as you suggest.
>>
>> > Module `Custom' does not exists. The problem may be two fold. Either
>> > a
>> > model was requested that's available in an extra bundle, e.g. a
>> > widget, or a
>> > custom model was requested, but it wasn't registered before first
>> > usage.
>>
>> What would be the solution for that? Sorry I am not sure what you mean
>> about having an older version of custom.js, or the imports and exports
>> being all wrong, because the custom.coffee works fine using bokeh
>> 0.12.3, but then running decaffeinate custom.coffee > and running the
>> custom.js results in the runtime error.
>
>
> Custom model handling is different between 0.12.3 and master
> (0.12.4-dev).
> Looking at your two first E-mails, it seems that you are mixing example
> code
> from 0.12.3 with bokeh 0.12.4-dev. That's not going to work. I suggest
> starting with [1] (which is the same code, just updated with new-style
> imports and exports).
>
> [1]
>
> https://github.com/bokeh/bokeh/blob/master/sphinx/source/docs/user_guide/examples/extensions_putting_together.py
>
> Mateusz
>
>>
>>
>> Thanks,
>> Alex
>>
>> On Wed, Nov 30, 2016 at 11:57 AM, Mateusz Paprocki >>>> >> <[email protected]> wrote:
>> > Hi,
>> >
>> > On Wed, Nov 30, 2016 at 7:22 PM, Alex Rice <[email protected]> >>>> >> > wrote:
>> >>
>> >> Hi Mateusz, Thanks for the info- this makes sense. I put the output
>> >> from decaffeinate into a gist
>> >>
>> >> https://gist.github.com/guidorice/df557a0e12f0d3b6831799c8ff44eae7
>> >>
>> >> If you can spot why it wont compile, that would be awesome. Or if
>> >> you
>> >> can point me to any other custom models using Js instead of
>> >> Coffeescript?
>> >
>> >
>> > This code does compile. It will fail at runtime, but that's a
>> > different
>> > thing. Maybe the problem is in how you include the implementation
>> > within
>> > a
>> > model? Instead having:
>> >
>> > class Custom(LayoutDOM):
>> > __implementation__ = CODE
>> >
>> > you should have
>> >
>> > from bokeh.util.compiler import JavaScript
>> >
>> > class Custom(LayoutDOM):
>> > __implementation__ = JavaScript(CODE)
>> >
>> > The earlier is just convenience for the default language
>> > (CoffeeScript).
>> >
>> > The code will fail at runtime, because imports and exports are all
>> > wrong.
>> > This may be due to using some older version of custom.js, e.g. mixing
>> > old
>> > documentation with new code. Note that custom models changed a lot
>> > since
>> > last release.
>> >
>> > Mateusz
>> >
>> >>
>> >> Best regards,
>> >> Alex
>> >>
>> >> On Wed, Nov 30, 2016 at 7:12 AM, Mateusz Paprocki >>>> >> >> <[email protected]> wrote:
>> >>
>> >> > JavaScript and ES2015 and parts of ES2017 are handled together
>> >> > with
>> >> > TypeScript. This is because TypeScript is an extension of
>> >> > ECMAScript,
>> >> > so
>> >> > we
>> >> > can compile everything with one compiler. Adding Babel is an
>> >> > option,
>> >> > however
>> >> > Babel is huge (binary-wise) and generates code I don't like. We
>> >> > also
>> >> > compile
>> >> > CoffeeScript this way as well. i.e. CoffeeScript gets compiled
>> >> > down
>> >> > to
>> >> > mixed
>> >> > ES5/ES2015 and then compiled once again with TypeScript, down to
>> >> > ES5.
>> >> >
>> >> > It would be useful to know the generated "decaffeinated" code to
>> >> > explain
>> >> > why
>> >> > compilation fails. Maybe imports/exports are wrapped somehow and
>> >> > that
>> >> > won't
>> >> > be allowed by TypeScript compiler (CoffeeScript code must must be
>> >> > compiled
>> >> > with "bare" option).
>> >> >
>> >> > Mateusz
>> >> >
>> >
>> >
>
>