DeserializationError: Bokeh server with custom labels for ticks

Hi all,

First of all thanks for developing Bokeh, I found it very powerful and useful to a data plotting and moreover plot customization with widgets.

As usual I’m trying to make custom tick labels along X axis, I used the 3 bars plotting example from here: http://stackoverflow.com/questions/37173230/how-do-i-use-custom-labels-for-ticks-in-bokeh

but because I need run bokeh server (not html like in the example), I did the following instructions from here: https://github.com/bokeh/bokeh/issues/3930

Like the-neworder suggested I created a new module with FixedTickFormatter:

from bokeh.util.compiler import CoffeeScript
from bokeh.core.properties import Dict, Int, String
from bokeh.models import TickFormatter




class FixedTickFormatter(TickFormatter):
"""

    Class used to allow custom axis tick labels on a bokeh chart
    Extends bokeh.model.formatters.TickFormatter
    """


    COFFEESCRIPT = """

        import {Model} from "model"
        import * as p from "core/properties"
        export class FixedTickFormatter extends Model
          type: 'FixedTickFormatter'
          doFormat: (ticks) ->
            labels = @get("labels")
            return (labels[tick] ? "" for tick in ticks)
          @define {
            labels: [ p.Any ]
          }
    """


    labels = Dict(Int, String, help="""

    A mapping of integer ticks values to their labels.
    """)


__implementation__ = CoffeeScript(COFFEESCRIPT)



and run Bokeh server like it explained inside the link above: bokeh serve visualize_server.py and so on...

This new module was found successfully and works fine for html (3 bars with custom labels were shown), but not for server. The code is below:


import pandas as pd

from bokeh.charts import Bar, output_file, show

from bokeh.client import push_session

from bokeh.plotting import curdoc, figure

from custom_ticks import FixedTickFormatter

from bokeh.layouts import layout

skills_list = [‘cheese making’, ‘squanching’, ‘leaving harsh criticisms’]

pct_counts = [25, 40, 1]

df = pd.DataFrame({‘skill’:skills_list, ‘pct jobs with skill’:pct_counts})

p = Bar(df, ‘index’, values=‘pct jobs with skill’, title=“Top skills for ___ jobs”, legend=False)

label_dict = {}

for i, s in enumerate(skills_list):

label_dict[int(i)] = str(s)

print label_dict

p.xaxis[0].formatter = FixedTickFormatter(labels=label_dict)

output_file(“bar.html”)

show(p)

‘’’

session = push_session(curdoc(), app_path=“/visualization_server”)

l = layout([[p]], sizing_mode=‘fixed’)

session.show(l)

session.loop_until_closed()

‘’’

In case of session using:


> ```
> ```
> 
> 
> ```

> ```
> ```
> session = push_session(curdoc(), app_path="/visualization_server")
> ```

> ```
> ```
> l = layout([[p]], sizing_mode='fixed')
> ```

> ```
> ```
> session.show(l)
> ```

> ```
> ```
> session.loop_until_closed()
> ```

I’ve got: DeserializationError(u’Int expected Integral, got1’,)

Could you please give an idea why? I have seen similar problem here: https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/zUE0i7LYwQg

But as it looks for me it’s another situation. Thank you!

What happens if you try

  labels = Dict(Float, String)

?

Thanks,

Bryan

···

On Feb 10, 2017, at 03:22, Boris Gribkov <[email protected]> wrote:

Hi all,

First of all thanks for developing Bokeh, I found it very powerful and useful to a data plotting and moreover plot customization with widgets.

As usual I'm trying to make custom tick labels along X axis, I used the 3 bars plotting example from here: How do I use custom labels for ticks in Bokeh? - Stack Overflow
but because I need run bokeh server (not html like in the example), I did the following instructions from here: Custom Extensions are not available when using bokeh.client · Issue #3930 · bokeh/bokeh · GitHub

Like the-neworder suggested I created a new module with FixedTickFormatter:

from bokeh.util.compiler import CoffeeScript
from bokeh.core.properties import Dict, Int, String
from bokeh.models import TickFormatter

class FixedTickFormatter(TickFormatter):
    """
    Class used to allow custom axis tick labels on a bokeh chart
    Extends bokeh.model.formatters.TickFormatter
    """

    COFFEESCRIPT = """
        import {Model} from "model"
        import * as p from "core/properties"
        export class FixedTickFormatter extends Model
          type: 'FixedTickFormatter'
          doFormat: (ticks) ->
            labels = @get("labels")
            return (labels[tick] ? "" for tick in ticks)
          @define {
            labels: [ p.Any ]
          }
    """

    labels = Dict(Int, String, help="""
    A mapping of integer ticks values to their labels.
    """)

    __implementation__ = CoffeeScript(COFFEESCRIPT)

and run Bokeh server like it explained inside the link above: bokeh serve visualize_server.py and so on...

This new module was found successfully and works fine for html (3 bars with custom labels were shown), but not for server. The code is below:

import pandas as pd
from bokeh.charts import Bar, output_file, show
from bokeh.client import push_session
from bokeh.plotting import curdoc, figure
from custom_ticks import FixedTickFormatter
from bokeh.layouts import layout

skills_list = ['cheese making', 'squanching', 'leaving harsh criticisms']
pct_counts = [25, 40, 1]
df = pd.DataFrame({'skill':skills_list, 'pct jobs with skill':pct_counts})
p = Bar(df, 'index', values='pct jobs with skill', title="Top skills for ___ jobs", legend=False)
label_dict = {}
for i, s in enumerate(skills_list):
    label_dict[int(i)] = str(s)

print label_dict
p.xaxis[0].formatter = FixedTickFormatter(labels=label_dict)
output_file("bar.html")
show(p)

'''
session = push_session(curdoc(), app_path="/visualization_server")
l = layout([[p]], sizing_mode='fixed')
session.show(l)
session.loop_until_closed()
'''

In case of session using:

session = push_session(curdoc(), app_path="/visualization_server")
l = layout([[p]], sizing_mode='fixed')
session.show(l)
session.loop_until_closed()

I've got: DeserializationError(u'Int expected Integral, got1',)

Could you please give an idea why? I have seen similar problem here: Redirecting to Google Groups
But as it looks for me it's another situation. Thank you!

--
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/ec2ea51b-ef17-47fb-a15b-ec0e9eec4d23%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan! Happy to see you here! )

in case of   labels = Dict(Float, String) 
I have got this: DeserializationError(u'Float expected Real, got 1',), I did't touch initial file, keeping this:
for i, s in enumerate(skills_list):

label_dict[int(i)] = str(s)

in case of:

for i, s in enumerate(skills_list):
label_dict[float(i)] = str(s)

→ DeserializationError(u’Float expected Real, got 0.0’,)


<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

понедельник, 13 февраля 2017 г., 19:21:07 UTC+3 пользователь Bryan Van de ven написал:
> What happens if you try
> 
> 
> 
>         labels = Dict(Float, String)
> 
> 
> ?
> 
> 
> 
> Thanks,
> 
> 
> 
> Bryan
> 
> 
> 
> 
> 
> 
> 
> 
> > On Feb 10, 2017, at 03:22, Boris Gribkov <[email protected]> wrote:
> 
> >
> > Hi all,
> >
> > First of all thanks for developing Bokeh, I found it very powerful and useful to a data plotting and moreover plot customization with widgets.
> 
> >
> > As usual I'm trying to make custom tick labels along X axis, I used the 3 bars plotting example from here: [http://stackoverflow.com/questions/37173230/how-do-i-use-custom-labels-for-ticks-in-bokeh](http://stackoverflow.com/questions/37173230/how-do-i-use-custom-labels-for-ticks-in-bokeh)
> 
> > but because I need run bokeh server (not html like in the example), I did the following instructions from here: [https://github.com/bokeh/bokeh/issues/3930](https://github.com/bokeh/bokeh/issues/3930)
> 
> >
> > Like the-neworder suggested I created a new module with FixedTickFormatter:
> 
> >
> >
> > from bokeh.util.compiler import CoffeeScript
> 
> > from bokeh.core.properties import Dict, Int, String
> 
> > from bokeh.models import TickFormatter
> 
> >
> >
> > class FixedTickFormatter(TickFormatter):
> 
> >     """
> 
> >     Class used to allow custom axis tick labels on a bokeh chart
> 
> >     Extends bokeh.model.formatters.TickFormatter
> 
> >     """
> 
> >
> >     COFFEESCRIPT =  """
> 
> >         import {Model} from "model"
> 
> >         import * as p from "core/properties"
> 
> >         export class FixedTickFormatter extends Model
> 
> >           type: 'FixedTickFormatter'
> 
> >           doFormat: (ticks) ->
> 
> >             labels = @get("labels")
> 
> >             return (labels[tick] ? "" for tick in ticks)
> 
> >           @define {
> 
> >             labels: [ p.Any ]
> 
> >           }
> 
> >     """
> 
> >
> >     labels = Dict(Int, String, help="""
> 
> >     A mapping of integer ticks values to their labels.
> 
> >     """)
> 
> >
> >     __implementation__ = CoffeeScript(COFFEESCRIPT)
> 
> >
> >
> >
> > and run Bokeh server like it explained inside the link above: bokeh serve visualize_server.py and so on...
> 
> >
> > This new module was found successfully and works fine for html (3 bars with custom labels were shown), but not for server. The code is below:
> 
> >
> >
> > import pandas as pd
> 
> > from bokeh.charts import Bar, output_file, show
> 
> > from bokeh.client import push_session
> 
> > from bokeh.plotting import curdoc, figure
> 
> > from custom_ticks import FixedTickFormatter
> 
> > from bokeh.layouts import layout
> 
> >
> >
> > skills_list = ['cheese making', 'squanching', 'leaving harsh criticisms']
> 
> > pct_counts = [25, 40, 1]
> 
> > df = pd.DataFrame({'skill':skills_list, 'pct jobs with skill':pct_counts})
> 
> > p = Bar(df, 'index', values='pct jobs with skill', title="Top skills for ___ jobs", legend=False)
> 
> > label_dict = {}
> 
> > for i, s in enumerate(skills_list):
> 
> >     label_dict[int(i)] = str(s)
> 
> >
> > print label_dict
> 
> > p.xaxis[0].formatter = FixedTickFormatter(labels=label_dict)
> 
> > output_file("bar.html")
> 
> > show(p)
> 
> >
> > '''
> 
> > session = push_session(curdoc(), app_path="/visualization_server")
> 
> > l = layout([[p]], sizing_mode='fixed')
> 
> > session.show(l)
> 
> > session.loop_until_closed()
> 
> > '''
> 
> >
> > In case of session using:
> 
> >
> > session = push_session(curdoc(), app_path="/visualization_server")
> 
> > l = layout([[p]], sizing_mode='fixed')
> 
> > session.show(l)
> 
> > session.loop_until_closed()
> 
> >
> > I've got: DeserializationError(u'Int expected Integral, got1',)
> 
> >
> > Could you please give an idea why? I have seen similar problem here: [https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/zUE0i7LYwQg](https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/zUE0i7LYwQg)
> 
> > But as it looks for me it's another situation. Thank you!
> 
> >
> >
> > --
> > 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/ec2ea51b-ef17-47fb-a15b-ec0e9eec4d23%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/ec2ea51b-ef17-47fb-a15b-ec0e9eec4d23%40continuum.io).
> 
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> 
> 
>

</details>

Well, that's very strange, and unfortunately I can't think of any explanations offhand. At this point I would suggest making a GitHub bug report issue with complete code and instructions to reproduce.

Thanks,

Bryan

···

On Feb 13, 2017, at 14:04, Boris Gribkov <[email protected]> wrote:

Hi Bryan! Happy to see you here! )

in case of labels = Dict(Float, String)
I have got this: DeserializationError(u'Float expected Real, got 1',), I did't touch initial file, keeping this:
for i, s in enumerate(skills_list):
    label_dict[int(i)] = str(s)

in case of:
for i, s in enumerate(skills_list):
    label_dict[float(i)] = str(s)
--> DeserializationError(u'Float expected Real, got 0.0',)

понедельник, 13 февраля 2017 г., 19:21:07 UTC+3 пользователь Bryan Van de ven написал:
What happens if you try

        labels = Dict(Float, String)

?

Thanks,

Bryan

> On Feb 10, 2017, at 03:22, Boris Gribkov <[email protected]> wrote:
>
> Hi all,
>
> First of all thanks for developing Bokeh, I found it very powerful and useful to a data plotting and moreover plot customization with widgets.
>
> As usual I'm trying to make custom tick labels along X axis, I used the 3 bars plotting example from here: How do I use custom labels for ticks in Bokeh? - Stack Overflow
> but because I need run bokeh server (not html like in the example), I did the following instructions from here: Custom Extensions are not available when using bokeh.client · Issue #3930 · bokeh/bokeh · GitHub
>
> Like the-neworder suggested I created a new module with FixedTickFormatter:
>
>
> from bokeh.util.compiler import CoffeeScript
> from bokeh.core.properties import Dict, Int, String
> from bokeh.models import TickFormatter
>
>
> class FixedTickFormatter(TickFormatter):
> """
> Class used to allow custom axis tick labels on a bokeh chart
> Extends bokeh.model.formatters.TickFormatter
> """
>
> COFFEESCRIPT = """
> import {Model} from "model"
> import * as p from "core/properties"
> export class FixedTickFormatter extends Model
> type: 'FixedTickFormatter'
> doFormat: (ticks) ->
> labels = @get("labels")
> return (labels[tick] ? "" for tick in ticks)
> @define {
> labels: [ p.Any ]
> }
> """
>
> labels = Dict(Int, String, help="""
> A mapping of integer ticks values to their labels.
> """)
>
> __implementation__ = CoffeeScript(COFFEESCRIPT)
>
>
>
> and run Bokeh server like it explained inside the link above: bokeh serve visualize_server.py and so on...
>
> This new module was found successfully and works fine for html (3 bars with custom labels were shown), but not for server. The code is below:
>
>
> import pandas as pd
> from bokeh.charts import Bar, output_file, show
> from bokeh.client import push_session
> from bokeh.plotting import curdoc, figure
> from custom_ticks import FixedTickFormatter
> from bokeh.layouts import layout
>
>
> skills_list = ['cheese making', 'squanching', 'leaving harsh criticisms']
> pct_counts = [25, 40, 1]
> df = pd.DataFrame({'skill':skills_list, 'pct jobs with skill':pct_counts})
> p = Bar(df, 'index', values='pct jobs with skill', title="Top skills for ___ jobs", legend=False)
> label_dict = {}
> for i, s in enumerate(skills_list):
> label_dict[int(i)] = str(s)
>
> print label_dict
> p.xaxis[0].formatter = FixedTickFormatter(labels=label_dict)
> output_file("bar.html")
> show(p)
>
> '''
> session = push_session(curdoc(), app_path="/visualization_server")
> l = layout([[p]], sizing_mode='fixed')
> session.show(l)
> session.loop_until_closed()
> '''
>
> In case of session using:
>
> session = push_session(curdoc(), app_path="/visualization_server")
> l = layout([[p]], sizing_mode='fixed')
> session.show(l)
> session.loop_until_closed()
>
> I've got: DeserializationError(u'Int expected Integral, got1',)
>
> Could you please give an idea why? I have seen similar problem here: Redirecting to Google Groups
> But as it looks for me it's another situation. Thank you!
>
>
> --
> 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 bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/ec2ea51b-ef17-47fb-a15b-ec0e9eec4d23%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/ca77d03e-5d77-43af-ae23-1479291e4cf5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks Bryan, will do it.
Another question, can I use labels near values like here Adding annotations — Bokeh 2.4.2 Documentation ?

Thank you!

No need to answer, found the solution for labels

···

четверг, 16 февраля 2017 г., 18:08:47 UTC+3 пользователь Boris Gribkov написал:

Thanks Bryan, will do it.
Another question, can I use labels near values like here http://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html#labels ?

Thank you!