Updating high level charts with a callback function

Can high-level charts like bar charts be updated with a callback function? The Bar constructor takes in a pandas DataFrame (or similar structure), while it appears that callback functions can only update data in the form of ColumnDataSource, meaning that callback functions can’t dynamically update a bar chart. Am I missing something?

Dear vijay,

···

This is how i do it now:

def update():

… df computations…

pbar = Bar(df, **kwargs)

rows.children[0] = pbar

#controls

btn = button(name=‘button’)

btn.on_click(update)

#layout

rows = row(graph1, graph2, btn)

#add2doc

curdoc.add_roots(rows)

To summarize, inside the update function you update a complete graph. In this case graph1 is child[0] which is replaced by pbar by calling the update function (clicking btn).

Hope this helps!

Ps I wrote this out of my head, forgive me for misspelling methods.

Best wishes,
Rakesh

On 1 jul. 2016, at 00:38, [email protected] wrote:

Can high-level charts like bar charts be updated with a callback function? The Bar constructor takes in a pandas DataFrame (or similar structure), while it appears that callback functions can only update data in the form of ColumnDataSource, meaning that callback functions can’t dynamically update a bar chart. Am I missing something?

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/0a9d7904-3e31-46e1-8d80-eeb41d266060%40continuum.io.

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

As Rakesh notes, for bokeh.charts the option is basically to replace entire charts at once. This is because the data that is input to the chart is a few steps removed from the ColumnDataSources that drive the drawing of glyphs. Think of a histogram: you input a 1-d series of data, something has to turn that into coordinates for all the rectangles. Those rectangle coordinates are what is in the ColumnDataSource, not the original series they were derived from.

If you want to be able to update just the data "in place" in an existing chart, I recommend using the slightly lower level bokeh.plotting API, where the relationship between the "original" data and the ColumnDataSources is much more straightforward.

Thanks,

Bryan

···

On Jun 30, 2016, at 7:12 PM, Rakesh Partapsing <[email protected]> wrote:

Dear vijay,

This is how i do it now:

def update():

      ..... df computations...
      pbar = Bar(df, **kwargs)
      rows.children[0] = pbar

#controls
btn = button(name='button')
btn.on_click(update)
#layout
rows = row(graph1, graph2, btn)
#add2doc
curdoc.add_roots(rows)

To summarize, inside the update function you update a complete graph. In this case graph1 is child[0] which is replaced by pbar by calling the update function (clicking btn).

Hope this helps!

Ps I wrote this out of my head, forgive me for misspelling methods.

Best wishes,
Rakesh

On 1 jul. 2016, at 00:38, [email protected] wrote:

Can high-level charts like bar charts be updated with a callback function? The Bar constructor takes in a pandas DataFrame (or similar structure), while it appears that callback functions can only update data in the form of ColumnDataSource, meaning that callback functions can't dynamically update a bar chart. Am I missing something?

--
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/0a9d7904-3e31-46e1-8d80-eeb41d266060%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/8AF571E2-629F-44EA-A8AD-EEEFA6852FE5%40gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks Rakesh and Bryan for the info. I tried Rakesh’s example with a Line chart, and it didn’t seems to work, code below. I’m pretty sure I’m doing something wrong here, but not sure what. Would anyone be able to provide any insight here please?

Thanks,

J

import numpy as np

from bokeh.charts import Line

from random import randint

from bokeh.plotting import curdoc

from bokeh.client.session import push_session

session = push_session(curdoc())

xyvalues = np.array([[randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)]])

line = Line(xyvalues, title=“line”, legend=None)

def update():

global line, xyvalues

xyvalues = np.array([[randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)]])

line = Line(xyvalues, title=“line”, legend=None)

curdoc().add_root(line)

curdoc().title = “my_title”

curdoc().add_periodic_callback(update, 1000)

session.show()

session.loop_until_closed()

···

On Friday, 1 July 2016 01:12:40 UTC+1, Raki wrote:

Dear vijay,

This is how i do it now:

def update():

… df computations…

pbar = Bar(df, **kwargs)

rows.children[0] = pbar

#controls

btn = button(name=‘button’)

btn.on_click(update)

#layout

rows = row(graph1, graph2, btn)

#add2doc

curdoc.add_roots(rows)

To summarize, inside the update function you update a complete graph. In this case graph1 is child[0] which is replaced by pbar by calling the update function (clicking btn).

Hope this helps!

Ps I wrote this out of my head, forgive me for misspelling methods.

Best wishes,
Rakesh

On 1 jul. 2016, at 00:38, [email protected] wrote:

Can high-level charts like bar charts be updated with a callback function? The Bar constructor takes in a pandas DataFrame (or similar structure), while it appears that callback functions can only update data in the form of ColumnDataSource, meaning that callback functions can’t dynamically update a bar chart. Am I missing something?

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/0a9d7904-3e31-46e1-8d80-eeb41d266060%40continuum.io.

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

Hi,

As mentioned in my earlier message, the different APIs serve different purposes and are not all equally suited for different use-cases. For interactive plots with callbacks, the bokeh.plotting API is much more suitabe than using bokeh.charts. Drawing lines is also a one-liner with bokeh.plotting, so there is really no additional overhead. There are numerous examples of updating lines, etc. from bokeh apps, so I have to suggest looking at and studying those, then trying to make small modifications to understand their function. It is often much better to start from a known working place when learning a new system. Here is a basic example that updates a line based on sliders:

  https://github.com/bokeh/bokeh/blob/master/examples/app/sliders.py

Thanks,

Bryan

···

On Sep 12, 2016, at 3:42 PM, jhappa <[email protected]> wrote:

Thanks Rakesh and Bryan for the info. I tried Rakesh's example with a Line chart, and it didn't seems to work, code below. I'm pretty sure I'm doing something wrong here, but not sure what. Would anyone be able to provide any insight here please?

Thanks,
J

import numpy as np
from bokeh.charts import Line
from random import randint
from bokeh.plotting import curdoc
from bokeh.client.session import push_session

session = push_session(curdoc())

xyvalues = np.array([[randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)]])
line = Line(xyvalues, title="line", legend=None)

def update():
    global line, xyvalues
    xyvalues = np.array([[randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)]])
    line = Line(xyvalues, title="line", legend=None)
    
curdoc().add_root(line)
curdoc().title = "my_title"
curdoc().add_periodic_callback(update, 1000)
  
session.show()
session.loop_until_closed()

On Friday, 1 July 2016 01:12:40 UTC+1, Raki wrote:
Dear vijay,

This is how i do it now:

def update():

      ..... df computations...
      pbar = Bar(df, **kwargs)
      rows.children[0] = pbar

#controls
btn = button(name='button')
btn.on_click(update)
#layout
rows = row(graph1, graph2, btn)
#add2doc
curdoc.add_roots(rows)

To summarize, inside the update function you update a complete graph. In this case graph1 is child[0] which is replaced by pbar by calling the update function (clicking btn).

Hope this helps!

Ps I wrote this out of my head, forgive me for misspelling methods.

Best wishes,
Rakesh

On 1 jul. 2016, at 00:38, vi...@yikyakapp.com wrote:

Can high-level charts like bar charts be updated with a callback function? The Bar constructor takes in a pandas DataFrame (or similar structure), while it appears that callback functions can only update data in the form of ColumnDataSource, meaning that callback functions can't dynamically update a bar chart. Am I missing something?

--
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/0a9d7904-3e31-46e1-8d80-eeb41d266060%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/afd1a24f-6d01-4d87-818b-96fab918384e%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

Yes but the problem is that Bar chart function/object is not available with bokeh.charts. I was searching alternative to Bar chart in bokeh.plotting but could not find the same. May be we have to use quad,rectangle, square or something and generate the co-ordinates with ourself.

Thanks,

Saurabh

···

On Tuesday, 13 September 2016 02:25:35 UTC+5:30, Bryan Van de ven wrote:

Hi,

As mentioned in my earlier message, the different APIs serve different purposes and are not all equally suited for different use-cases. For interactive plots with callbacks, the bokeh.plotting API is much more suitabe than using bokeh.charts. Drawing lines is also a one-liner with bokeh.plotting, so there is really no additional overhead. There are numerous examples of updating lines, etc. from bokeh apps, so I have to suggest looking at and studying those, then trying to make small modifications to understand their function. It is often much better to start from a known working place when learning a new system. Here is a basic example that updates a line based on sliders:

    [https://github.com/bokeh/bokeh/blob/master/examples/app/sliders.py](https://github.com/bokeh/bokeh/blob/master/examples/app/sliders.py)

Thanks,

Bryan

On Sep 12, 2016, at 3:42 PM, jhappa [email protected] wrote:

Thanks Rakesh and Bryan for the info. I tried Rakesh’s example with a Line chart, and it didn’t seems to work, code below. I’m pretty sure I’m doing something wrong here, but not sure what. Would anyone be able to provide any insight here please?

Thanks,

J

import numpy as np

from bokeh.charts import Line

from random import randint

from bokeh.plotting import curdoc

from bokeh.client.session import push_session

session = push_session(curdoc())

xyvalues = np.array([[randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)]])

line = Line(xyvalues, title=“line”, legend=None)

def update():

global line, xyvalues
xyvalues = np.array([[randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)]])
line = Line(xyvalues, title="line", legend=None)

curdoc().add_root(line)

curdoc().title = “my_title”

curdoc().add_periodic_callback(update, 1000)

session.show()
session.loop_until_closed()

On Friday, 1 July 2016 01:12:40 UTC+1, Raki wrote:

Dear vijay,

This is how i do it now:

def update():

  ..... df computations...
  pbar = Bar(df, **kwargs)
  rows.children[0] = pbar

#controls

btn = button(name=‘button’)

btn.on_click(update)

#layout

rows = row(graph1, graph2, btn)

#add2doc

curdoc.add_roots(rows)

To summarize, inside the update function you update a complete graph. In this case graph1 is child[0] which is replaced by pbar by calling the update function (clicking btn).

Hope this helps!

Ps I wrote this out of my head, forgive me for misspelling methods.

Best wishes,

Rakesh

On 1 jul. 2016, at 00:38, [email protected] wrote:

Can high-level charts like bar charts be updated with a callback function? The Bar constructor takes in a pandas DataFrame (or similar structure), while it appears that callback functions can only update data in the form of ColumnDataSource, meaning that callback functions can’t dynamically update a bar chart. Am I missing something?


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/0a9d7904-3e31-46e1-8d80-eeb41d266060%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/afd1a24f-6d01-4d87-818b-96fab918384e%40continuum.io.

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

Hi,

There are very new additions to bokeh.plotting, vbar and hbar, that should creating bar-like plots simpler:

  https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py

They do not do as much as bokeh.charts.Bar, there are still coordinates that have to be computed, though they will probably be simpler that for quad or rect. However, if the priority is more interactivity, using a slightly lower level interface is the tradeoff that has to be made.

Thanks,

Bryan

···

On Sep 20, 2016, at 11:06 PM, Saurabh Heda <[email protected]> wrote:

Hi Bryan,

Yes but the problem is that Bar chart function/object is not available with bokeh.charts. I was searching alternative to Bar chart in bokeh.plotting but could not find the same. May be we have to use quad,rectangle, square or something and generate the co-ordinates with ourself.

Thanks,
Saurabh

On Tuesday, 13 September 2016 02:25:35 UTC+5:30, Bryan Van de ven wrote:
Hi,

As mentioned in my earlier message, the different APIs serve different purposes and are not all equally suited for different use-cases. For interactive plots with callbacks, the bokeh.plotting API is much more suitabe than using bokeh.charts. Drawing lines is also a one-liner with bokeh.plotting, so there is really no additional overhead. There are numerous examples of updating lines, etc. from bokeh apps, so I have to suggest looking at and studying those, then trying to make small modifications to understand their function. It is often much better to start from a known working place when learning a new system. Here is a basic example that updates a line based on sliders:

        https://github.com/bokeh/bokeh/blob/master/examples/app/sliders.py

Thanks,

Bryan

> On Sep 12, 2016, at 3:42 PM, jhappa <[email protected]> wrote:
>
>
> Thanks Rakesh and Bryan for the info. I tried Rakesh's example with a Line chart, and it didn't seems to work, code below. I'm pretty sure I'm doing something wrong here, but not sure what. Would anyone be able to provide any insight here please?
>
> Thanks,
> J
>
> import numpy as np
> from bokeh.charts import Line
> from random import randint
> from bokeh.plotting import curdoc
> from bokeh.client.session import push_session
>
> session = push_session(curdoc())
>
> xyvalues = np.array([[randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)]])
> line = Line(xyvalues, title="line", legend=None)
>
> def update():
> global line, xyvalues
> xyvalues = np.array([[randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)], [randint(0, 100) for i in range(10)]])
> line = Line(xyvalues, title="line", legend=None)
>
> curdoc().add_root(line)
> curdoc().title = "my_title"
> curdoc().add_periodic_callback(update, 1000)
>
> session.show()
> session.loop_until_closed()
>
>
>
> On Friday, 1 July 2016 01:12:40 UTC+1, Raki wrote:
> Dear vijay,
>
> This is how i do it now:
>
> def update():
>
> ..... df computations...
> pbar = Bar(df, **kwargs)
> rows.children[0] = pbar
>
> #controls
> btn = button(name='button')
> btn.on_click(update)
> #layout
> rows = row(graph1, graph2, btn)
> #add2doc
> curdoc.add_roots(rows)
>
> To summarize, inside the update function you update a complete graph. In this case graph1 is child[0] which is replaced by pbar by calling the update function (clicking btn).
>
> Hope this helps!
>
> Ps I wrote this out of my head, forgive me for misspelling methods.
>
> Best wishes,
> Rakesh
>
> On 1 jul. 2016, at 00:38, vi...@yikyakapp.com wrote:
>
>> Can high-level charts like bar charts be updated with a callback function? The Bar constructor takes in a pandas DataFrame (or similar structure), while it appears that callback functions can only update data in the form of ColumnDataSource, meaning that callback functions can't dynamically update a bar chart. Am I missing something?
>>
>> --
>> 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/0a9d7904-3e31-46e1-8d80-eeb41d266060%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 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/afd1a24f-6d01-4d87-818b-96fab918384e%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/031cb2d5-84a0-431b-92c4-620d12ae9ec8%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.