Callbacks from select tool

Dear Bokeh community,

From a drop down selection I would like to have a plot updated for what has been selected.

This means a dataFrame has to be filtered first.

I am quite new to bokeh and callbacks.

For now I have:

“”"

import bokeh

from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file

from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool

from bokeh.models.widgets import Select

from bokeh.io import hplot

print(“Bokeh version: %s” %bokeh.version)

print(“Panda version: %s” %pd.version)

output_notebook()

output_file(“NozzleOut.html”)

_tools_to_show = ‘box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap’

def callbackMedium(uniqueMediaLst, df_m):

#data

medium = cb_obj.get(‘value’)

df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)

df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)

#plot

p = figure(plot_width=600,

plot_height=600,

tools=_tools_to_show,

title=“NozzleOuts. NFD-Count: %s. Medium: %s” %(nfdCount, medium) ,

y_range=Range1d(start=0.0, end=nfdCount+100))

p.xaxis.axis_label = ‘zPos[dotNr]’

p.xaxis.major_label_orientation = 90

p.yaxis.axis_label = ‘Drops[#]’

i = 0

for (name, series) in df_tot.iteritems():

need to repmat the name to be same dimension as index

name_for_display = np.tile(name, [len(df_tot.index),1])

source = ColumnDataSource({‘x’: df_tot.index, ‘y’: series.values, ‘series_name’: name_for_display})

trouble formating x as datestring, so pre-formating and using an extra column. It’s not pretty but it works.

p.scatter(‘x’, ‘y’, fill_alpha=0.6, size=5, source = source, color=colorRange[i])

hover = p.select(dict(type=HoverTool))

hover.tooltips = [(“ColHead”, “@series_name”), (“Nozzle”, “@x”), (“Drops”, “@y”)]

hover.mode = ‘mouse’

i +=1

return p

select = Select(title=“Select Medium:”, value=“All”, options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))

show(hplot(p, select))

“”"

Explanation:

A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.

Question:

I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?

Hi,

There is an important point to clarify: namely that:

  CustomJS callbacks *CANNOT EXECUTE REAL PYTHON CODE*

They are JavaScript, and execute only in the browser. Even if they are written using "CustomJS.from_py_func", all that does is proiide a convenient way to *compile* python *into* JavaScript. In the end, there is still *only* JavaScript executing, and *only* in the browser.

If you need to run actual python code in response to some user interaction (a widget or plot selection, say) then you will have to create a Bokeh Application that is run and hosted on a Bokeh server.

Bryan

···

On Mar 22, 2016, at 10:10 AM, [email protected] wrote:

Dear Bokeh community,

From a drop down selection I would like to have a plot updated for what has been selected.
This means a dataFrame has to be filtered first.

I am quite new to bokeh and callbacks.

For now I have:

"""
import bokeh
from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file
from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool
from bokeh.models.widgets import Select
from bokeh.io import hplot

print("Bokeh version: %s" %bokeh.__version__)
print("Panda version: %s" %pd.__version__)

output_notebook()

output_file("NozzleOut.html")

_tools_to_show = 'box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap'

def callbackMedium(uniqueMediaLst, df_m):
    #data
    medium = cb_obj.get('value')
    df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)
    df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)
    
    #plot
    p = figure(plot_width=600,
           plot_height=600,
           tools=_tools_to_show,
           title="NozzleOuts. NFD-Count: %s. Medium: %s" %(nfdCount, medium) ,
           y_range=Range1d(start=0.0, end=nfdCount+100))
    p.xaxis.axis_label = 'zPos[dotNr]'
    p.xaxis.major_label_orientation = 90
    p.yaxis.axis_label = 'Drops[#]'

    i = 0
    for (name, series) in df_tot.iteritems():
        # need to repmat the name to be same dimension as index
        name_for_display = np.tile(name, [len(df_tot.index),1])

        source = ColumnDataSource({'x': df_tot.index, 'y': series.values, 'series_name': name_for_display})
        # trouble formating x as datestring, so pre-formating and using an extra column. It's not pretty but it works.

        p.scatter('x', 'y', fill_alpha=0.6, size=5, source = source, color=colorRange[i])

        hover = p.select(dict(type=HoverTool))
        hover.tooltips = [("ColHead", "@series_name"), ("Nozzle", "@x"), ("Drops", "@y")]
        hover.mode = 'mouse'

        i +=1
    return p

select = Select(title="Select Medium:", value="All", options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))
    
show(hplot(p, select))
"""

Explanation:
A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.

Question:
I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?

--
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/4c4120c7-f008-4887-97b0-6d5aa3af0194%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I should add: it also may be possible to do the filtering in the browser, using only JavaScript. If your data is not large and there are not many filter options, you could pre-filter and send all the possible combinations into the browser as separate column data sources, then the CustomJS call back can just switch between them. Or possibly actually writing JavaScript to do the filtering by hand, it's hard to say more without more details. The point is there is no access to pandas or numpy or anything like that in the browser.

Bryan

···

On Mar 22, 2016, at 10:18 AM, Bryan Van de Ven <[email protected]> wrote:

Hi,

There is an important point to clarify: namely that:

  CustomJS callbacks *CANNOT EXECUTE REAL PYTHON CODE*

They are JavaScript, and execute only in the browser. Even if they are written using "CustomJS.from_py_func", all that does is proiide a convenient way to *compile* python *into* JavaScript. In the end, there is still *only* JavaScript executing, and *only* in the browser.

If you need to run actual python code in response to some user interaction (a widget or plot selection, say) then you will have to create a Bokeh Application that is run and hosted on a Bokeh server.

Bryan

On Mar 22, 2016, at 10:10 AM, [email protected] wrote:

Dear Bokeh community,

From a drop down selection I would like to have a plot updated for what has been selected.
This means a dataFrame has to be filtered first.

I am quite new to bokeh and callbacks.

For now I have:

"""
import bokeh
from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file
from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool
from bokeh.models.widgets import Select
from bokeh.io import hplot

print("Bokeh version: %s" %bokeh.__version__)
print("Panda version: %s" %pd.__version__)

output_notebook()

output_file("NozzleOut.html")

_tools_to_show = 'box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap'

def callbackMedium(uniqueMediaLst, df_m):
   #data
   medium = cb_obj.get('value')
   df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)
   df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)

   #plot
   p = figure(plot_width=600,
          plot_height=600,
          tools=_tools_to_show,
          title="NozzleOuts. NFD-Count: %s. Medium: %s" %(nfdCount, medium) ,
          y_range=Range1d(start=0.0, end=nfdCount+100))
   p.xaxis.axis_label = 'zPos[dotNr]'
   p.xaxis.major_label_orientation = 90
   p.yaxis.axis_label = 'Drops[#]'

   i = 0
   for (name, series) in df_tot.iteritems():
       # need to repmat the name to be same dimension as index
       name_for_display = np.tile(name, [len(df_tot.index),1])

       source = ColumnDataSource({'x': df_tot.index, 'y': series.values, 'series_name': name_for_display})
       # trouble formating x as datestring, so pre-formating and using an extra column. It's not pretty but it works.

       p.scatter('x', 'y', fill_alpha=0.6, size=5, source = source, color=colorRange[i])

       hover = p.select(dict(type=HoverTool))
       hover.tooltips = [("ColHead", "@series_name"), ("Nozzle", "@x"), ("Drops", "@y")]
       hover.mode = 'mouse'

       i +=1
   return p

select = Select(title="Select Medium:", value="All", options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))

show(hplot(p, select))
"""

Explanation:
A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.

Question:
I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?

--
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/4c4120c7-f008-4887-97b0-6d5aa3af0194%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Dear Bryan,

Thank you for your quick reply.

Actually I was aware CustomJS only reads JS, but I wrote it up like to clarify what I want to do: 1. updating a dataframe and 2. the plot After selection of something (in my case ‘medium’).

I have large data and ‘medium’ can be quite a long list. Moreover my columndataSource and figure p are updated inside a for-loop to be able to plot all columns from the df (with index = x-axis and columnName = legend item)
I can’t move the callback function and dropdown box inside the for-loop either, because then I could do the filtering by JS. Or do I miss anything?

The only remaining option I could try would then be to use a server as you said.

Could you maybe rewrite this code for me to understand where to start? That would be really helpful since I feel kind of stuck now.

Best wishes,

Rakesh

···

On Tuesday, March 22, 2016 at 4:22:34 PM UTC+1, Bryan Van de ven wrote:

I should add: it also may be possible to do the filtering in the browser, using only JavaScript. If your data is not large and there are not many filter options, you could pre-filter and send all the possible combinations into the browser as separate column data sources, then the CustomJS call back can just switch between them. Or possibly actually writing JavaScript to do the filtering by hand, it’s hard to say more without more details. The point is there is no access to pandas or numpy or anything like that in the browser.

Bryan

On Mar 22, 2016, at 10:18 AM, Bryan Van de Ven [email protected] wrote:

Hi,

There is an important point to clarify: namely that:

    CustomJS callbacks *CANNOT EXECUTE REAL PYTHON CODE*

They are JavaScript, and execute only in the browser. Even if they are written using “CustomJS.from_py_func”, all that does is proiide a convenient way to compile python into JavaScript. In the end, there is still only JavaScript executing, and only in the browser.

If you need to run actual python code in response to some user interaction (a widget or plot selection, say) then you will have to create a Bokeh Application that is run and hosted on a Bokeh server.

Bryan

On Mar 22, 2016, at 10:10 AM, [email protected] wrote:

Dear Bokeh community,

From a drop down selection I would like to have a plot updated for what has been selected.

This means a dataFrame has to be filtered first.

I am quite new to bokeh and callbacks.

For now I have:

“”"

import bokeh

from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file

from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool

from bokeh.models.widgets import Select

from bokeh.io import hplot

print(“Bokeh version: %s” %bokeh.version)

print(“Panda version: %s” %pd.version)

output_notebook()

output_file(“NozzleOut.html”)

_tools_to_show = ‘box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap’

def callbackMedium(uniqueMediaLst, df_m):

#data

medium = cb_obj.get(‘value’)

df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)

df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)

#plot

p = figure(plot_width=600,
plot_height=600,
tools=_tools_to_show,

      title="NozzleOuts. NFD-Count: %s. Medium: %s" %(nfdCount, medium) ,
      y_range=Range1d(start=0.0, end=nfdCount+100))

p.xaxis.axis_label = ‘zPos[dotNr]’

p.xaxis.major_label_orientation = 90

p.yaxis.axis_label = ‘Drops[#]’

i = 0

for (name, series) in df_tot.iteritems():

   # need to repmat the name to be same dimension as index
   name_for_display = np.tile(name, [len(df_tot.index),1])
   source = ColumnDataSource({'x': df_tot.index, 'y': series.values, 'series_name': name_for_display})
   # trouble formating x as datestring, so pre-formating and using an extra column. It's not pretty but it works.
   p.scatter('x', 'y', fill_alpha=0.6, size=5, source = source, color=colorRange[i])    

   hover = p.select(dict(type=HoverTool))
   hover.tooltips = [("ColHead", "@series_name"), ("Nozzle", "@x"), ("Drops", "@y")]
   hover.mode = 'mouse'
   i +=1

return p

select = Select(title=“Select Medium:”, value=“All”, options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))

show(hplot(p, select))

“”"

Explanation:

A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.

Question:

I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?


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/4c4120c7-f008-4887-97b0-6d5aa3af0194%40continuum.io.

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

Hi Rakesh,

While I want to be able to help as many people as possible have a good experience with Bokeh, rewriting code at this scale is simply not something I have the time or bandwidth to do, unfortunately. Others might be able and willing to offer support at the level, perhaps. In any case the "IMDB" server example does filtering from dataframes, hopefully it can serve as a useful reference.

example: http://demo.bokehplots.com/apps/movies

code: https://github.com/bokeh/bokeh/tree/master/examples/app/movies

Thanks,

Bryan

···

On Mar 23, 2016, at 6:38 AM, [email protected] wrote:

Dear Bryan,

Thank you for your quick reply.

Actually I was aware CustomJS only reads JS, but I wrote it up like to clarify what I want to do: 1. updating a dataframe and 2. the plot After selection of something (in my case 'medium').
I have large data and 'medium' can be quite a long list. Moreover my columndataSource and figure p are updated inside a for-loop to be able to plot all columns from the df (with index = x-axis and columnName = legend item)
I can't move the callback function and dropdown box inside the for-loop either, because then I could do the filtering by JS. Or do I miss anything?

The only remaining option I could try would then be to use a server as you said.
Could you maybe rewrite this code for me to understand where to start? That would be really helpful since I feel kind of stuck now.

Best wishes,
Rakesh

On Tuesday, March 22, 2016 at 4:22:34 PM UTC+1, Bryan Van de ven wrote:
I should add: it also may be possible to do the filtering in the browser, using only JavaScript. If your data is not large and there are not many filter options, you could pre-filter and send all the possible combinations into the browser as separate column data sources, then the CustomJS call back can just switch between them. Or possibly actually writing JavaScript to do the filtering by hand, it's hard to say more without more details. The point is there is no access to pandas or numpy or anything like that in the browser.

Bryan

> On Mar 22, 2016, at 10:18 AM, Bryan Van de Ven <[email protected]> wrote:
>
> Hi,
>
> There is an important point to clarify: namely that:
>
> CustomJS callbacks *CANNOT EXECUTE REAL PYTHON CODE*
>
> They are JavaScript, and execute only in the browser. Even if they are written using "CustomJS.from_py_func", all that does is proiide a convenient way to *compile* python *into* JavaScript. In the end, there is still *only* JavaScript executing, and *only* in the browser.
>
> If you need to run actual python code in response to some user interaction (a widget or plot selection, say) then you will have to create a Bokeh Application that is run and hosted on a Bokeh server.
>
> Bryan
>
>
>> On Mar 22, 2016, at 10:10 AM, [email protected] wrote:
>>
>> Dear Bokeh community,
>>
>> From a drop down selection I would like to have a plot updated for what has been selected.
>> This means a dataFrame has to be filtered first.
>>
>> I am quite new to bokeh and callbacks.
>>
>> For now I have:
>>
>> """
>> import bokeh
>> from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file
>> from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool
>> from bokeh.models.widgets import Select
>> from bokeh.io import hplot
>>
>> print("Bokeh version: %s" %bokeh.__version__)
>> print("Panda version: %s" %pd.__version__)
>>
>> output_notebook()
>>
>> output_file("NozzleOut.html")
>>
>> _tools_to_show = 'box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap'
>>
>> def callbackMedium(uniqueMediaLst, df_m):
>> #data
>> medium = cb_obj.get('value')
>> df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)
>> df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)
>>
>> #plot
>> p = figure(plot_width=600,
>> plot_height=600,
>> tools=_tools_to_show,
>> title="NozzleOuts. NFD-Count: %s. Medium: %s" %(nfdCount, medium) ,
>> y_range=Range1d(start=0.0, end=nfdCount+100))
>> p.xaxis.axis_label = 'zPos[dotNr]'
>> p.xaxis.major_label_orientation = 90
>> p.yaxis.axis_label = 'Drops[#]'
>>
>> i = 0
>> for (name, series) in df_tot.iteritems():
>> # need to repmat the name to be same dimension as index
>> name_for_display = np.tile(name, [len(df_tot.index),1])
>>
>> source = ColumnDataSource({'x': df_tot.index, 'y': series.values, 'series_name': name_for_display})
>> # trouble formating x as datestring, so pre-formating and using an extra column. It's not pretty but it works.
>>
>> p.scatter('x', 'y', fill_alpha=0.6, size=5, source = source, color=colorRange[i])
>>
>> hover = p.select(dict(type=HoverTool))
>> hover.tooltips = [("ColHead", "@series_name"), ("Nozzle", "@x"), ("Drops", "@y")]
>> hover.mode = 'mouse'
>>
>> i +=1
>> return p
>>
>> select = Select(title="Select Medium:", value="All", options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))
>>
>> show(hplot(p, select))
>> """
>>
>> Explanation:
>> A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.
>>
>> Question:
>> I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?
>>
>> --
>> 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/4c4120c7-f008-4887-97b0-6d5aa3af0194%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/303496b7-4a95-4517-b0bf-0df48e8dfbf9%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,

Again thank you for your quick respons.

Just two hours ago I found the movies and weather example that should cover exactly my issue.

The only problem is, they don’t work (I tried on chrome and IE).

  • When I click your example link I get a blank screen.

  • When I run the code with ‘bokeh serve --show movies’ I also get a blank screen

(I also think the main.py should be movies.py, and the manual should say: run bokeh serve --show movies.py (with the .py)

Can you check what is wrong with these 2 examples?

p.s. the other examples on http://demo.bokehplots.com/ do work!

Regards,

Rakesh

···

On Wed, Mar 23, 2016 at 4:52 PM, Bryan Van de Ven [email protected] wrote:

Hi Rakesh,

While I want to be able to help as many people as possible have a good experience with Bokeh, rewriting code at this scale is simply not something I have the time or bandwidth to do, unfortunately. Others might be able and willing to offer support at the level, perhaps. In any case the “IMDB” server example does filtering from dataframes, hopefully it can serve as a useful reference.

example: http://demo.bokehplots.com/apps/movies

code: https://github.com/bokeh/bokeh/tree/master/examples/app/movies

Thanks,

Bryan

On Mar 23, 2016, at 6:38 AM, [email protected] wrote:

Dear Bryan,

Thank you for your quick reply.

Actually I was aware CustomJS only reads JS, but I wrote it up like to clarify what I want to do: 1. updating a dataframe and 2. the plot After selection of something (in my case ‘medium’).

I have large data and ‘medium’ can be quite a long list. Moreover my columndataSource and figure p are updated inside a for-loop to be able to plot all columns from the df (with index = x-axis and columnName = legend item)

I can’t move the callback function and dropdown box inside the for-loop either, because then I could do the filtering by JS. Or do I miss anything?

The only remaining option I could try would then be to use a server as you said.

Could you maybe rewrite this code for me to understand where to start? That would be really helpful since I feel kind of stuck now.

Best wishes,

Rakesh

On Tuesday, March 22, 2016 at 4:22:34 PM UTC+1, Bryan Van de ven wrote:

I should add: it also may be possible to do the filtering in the browser, using only JavaScript. If your data is not large and there are not many filter options, you could pre-filter and send all the possible combinations into the browser as separate column data sources, then the CustomJS call back can just switch between them. Or possibly actually writing JavaScript to do the filtering by hand, it’s hard to say more without more details. The point is there is no access to pandas or numpy or anything like that in the browser.

Bryan

On Mar 22, 2016, at 10:18 AM, Bryan Van de Ven [email protected] wrote:

Hi,

There is an important point to clarify: namely that:

    CustomJS callbacks *CANNOT EXECUTE REAL PYTHON CODE*

They are JavaScript, and execute only in the browser. Even if they are written using “CustomJS.from_py_func”, all that does is proiide a convenient way to compile python into JavaScript. In the end, there is still only JavaScript executing, and only in the browser.

If you need to run actual python code in response to some user interaction (a widget or plot selection, say) then you will have to create a Bokeh Application that is run and hosted on a Bokeh server.

Bryan

On Mar 22, 2016, at 10:10 AM, [email protected] wrote:

Dear Bokeh community,

From a drop down selection I would like to have a plot updated for what has been selected.

This means a dataFrame has to be filtered first.

I am quite new to bokeh and callbacks.

For now I have:

“”"

import bokeh

from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file

from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool

from bokeh.models.widgets import Select

from bokeh.io import hplot

print(“Bokeh version: %s” %bokeh.version)

print(“Panda version: %s” %pd.version)

output_notebook()

output_file(“NozzleOut.html”)

_tools_to_show = ‘box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap’

def callbackMedium(uniqueMediaLst, df_m):

#data

medium = cb_obj.get(‘value’)

df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)

df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)

#plot

p = figure(plot_width=600,

      plot_height=600,
      tools=_tools_to_show,
      title="NozzleOuts. NFD-Count: %s. Medium: %s" %(nfdCount, medium) ,
      y_range=Range1d(start=0.0, end=nfdCount+100))

p.xaxis.axis_label = ‘zPos[dotNr]’

p.xaxis.major_label_orientation = 90

p.yaxis.axis_label = ‘Drops[#]’

i = 0

for (name, series) in df_tot.iteritems():

   # need to repmat the name to be same dimension as index
   name_for_display = np.tile(name, [len(df_tot.index),1])
   source = ColumnDataSource({'x': df_tot.index, 'y': series.values, 'series_name': name_for_display})
   # trouble formating x as datestring, so pre-formating and using an extra column. It's not pretty but it works.
   p.scatter('x', 'y', fill_alpha=0.6, size=5, source = source, color=colorRange[i])
   hover = p.select(dict(type=HoverTool))
   hover.tooltips = [("ColHead", "@series_name"), ("Nozzle", "@x"), ("Drops", "@y")]
   hover.mode = 'mouse'
   i +=1

return p

select = Select(title=“Select Medium:”, value=“All”, options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))

show(hplot(p, select))

“”"

Explanation:

A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.

Question:

I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?

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/4c4120c7-f008-4887-97b0-6d5aa3af0194%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/303496b7-4a95-4517-b0bf-0df48e8dfbf9%40continuum.io.

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

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ROKMK24KzLY/unsubscribe.

To unsubscribe from this group and all its topics, 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/FC0E89BD-0AB7-48D9-89C4-6D8AE9A35ECA%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Never mind…got it to work :wink:

···

On Wed, Mar 23, 2016 at 4:52 PM, Bryan Van de Ven [email protected] wrote:

Hi Rakesh,

While I want to be able to help as many people as possible have a good experience with Bokeh, rewriting code at this scale is simply not something I have the time or bandwidth to do, unfortunately. Others might be able and willing to offer support at the level, perhaps. In any case the “IMDB” server example does filtering from dataframes, hopefully it can serve as a useful reference.

example: http://demo.bokehplots.com/apps/movies

code: https://github.com/bokeh/bokeh/tree/master/examples/app/movies

Thanks,

Bryan

On Mar 23, 2016, at 6:38 AM, [email protected] wrote:

Dear Bryan,

Thank you for your quick reply.

Actually I was aware CustomJS only reads JS, but I wrote it up like to clarify what I want to do: 1. updating a dataframe and 2. the plot After selection of something (in my case ‘medium’).

I have large data and ‘medium’ can be quite a long list. Moreover my columndataSource and figure p are updated inside a for-loop to be able to plot all columns from the df (with index = x-axis and columnName = legend item)

I can’t move the callback function and dropdown box inside the for-loop either, because then I could do the filtering by JS. Or do I miss anything?

The only remaining option I could try would then be to use a server as you said.

Could you maybe rewrite this code for me to understand where to start? That would be really helpful since I feel kind of stuck now.

Best wishes,

Rakesh

On Tuesday, March 22, 2016 at 4:22:34 PM UTC+1, Bryan Van de ven wrote:

I should add: it also may be possible to do the filtering in the browser, using only JavaScript. If your data is not large and there are not many filter options, you could pre-filter and send all the possible combinations into the browser as separate column data sources, then the CustomJS call back can just switch between them. Or possibly actually writing JavaScript to do the filtering by hand, it’s hard to say more without more details. The point is there is no access to pandas or numpy or anything like that in the browser.

Bryan

On Mar 22, 2016, at 10:18 AM, Bryan Van de Ven [email protected] wrote:

Hi,

There is an important point to clarify: namely that:

    CustomJS callbacks *CANNOT EXECUTE REAL PYTHON CODE*

They are JavaScript, and execute only in the browser. Even if they are written using “CustomJS.from_py_func”, all that does is proiide a convenient way to compile python into JavaScript. In the end, there is still only JavaScript executing, and only in the browser.

If you need to run actual python code in response to some user interaction (a widget or plot selection, say) then you will have to create a Bokeh Application that is run and hosted on a Bokeh server.

Bryan

On Mar 22, 2016, at 10:10 AM, [email protected] wrote:

Dear Bokeh community,

From a drop down selection I would like to have a plot updated for what has been selected.

This means a dataFrame has to be filtered first.

I am quite new to bokeh and callbacks.

For now I have:

“”"

import bokeh

from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file

from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool

from bokeh.models.widgets import Select

from bokeh.io import hplot

print(“Bokeh version: %s” %bokeh.version)

print(“Panda version: %s” %pd.version)

output_notebook()

output_file(“NozzleOut.html”)

_tools_to_show = ‘box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap’

def callbackMedium(uniqueMediaLst, df_m):

#data

medium = cb_obj.get(‘value’)

df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)

df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)

#plot

p = figure(plot_width=600,

      plot_height=600,
      tools=_tools_to_show,
      title="NozzleOuts. NFD-Count: %s. Medium: %s" %(nfdCount, medium) ,
      y_range=Range1d(start=0.0, end=nfdCount+100))

p.xaxis.axis_label = ‘zPos[dotNr]’

p.xaxis.major_label_orientation = 90

p.yaxis.axis_label = ‘Drops[#]’

i = 0

for (name, series) in df_tot.iteritems():

   # need to repmat the name to be same dimension as index
   name_for_display = np.tile(name, [len(df_tot.index),1])
   source = ColumnDataSource({'x': df_tot.index, 'y': series.values, 'series_name': name_for_display})
   # trouble formating x as datestring, so pre-formating and using an extra column. It's not pretty but it works.
   p.scatter('x', 'y', fill_alpha=0.6, size=5, source = source, color=colorRange[i])
   hover = p.select(dict(type=HoverTool))
   hover.tooltips = [("ColHead", "@series_name"), ("Nozzle", "@x"), ("Drops", "@y")]
   hover.mode = 'mouse'
   i +=1

return p

select = Select(title=“Select Medium:”, value=“All”, options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))

show(hplot(p, select))

“”"

Explanation:

A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.

Question:

I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?

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/4c4120c7-f008-4887-97b0-6d5aa3af0194%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/303496b7-4a95-4517-b0bf-0df48e8dfbf9%40continuum.io.

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

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/ROKMK24KzLY/unsubscribe.

To unsubscribe from this group and all its topics, 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/FC0E89BD-0AB7-48D9-89C4-6D8AE9A35ECA%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Dear Bryan,

I almost got it to work on my dashboard. I use the ‘weather’ example from ‘url=https://github.com/bokeh/bokeh/tree/master/examples/app/weather’

The only remaining question I have is if the update function can be used to update a DataFrame instead of a ColumnDataSource?? Like:

def update(attrname, old, new):

global nfdCount

medium = medium_select.value

tit = “NFD-Count: %d | Medium: %s.” %(nfdCount,medium)

plot.title = tit

df_tot, nfdCount = get_dataset(df_m, medium)

df_tot.update(df_tot)

set up initial data

medium = FnameAll

medium_select = Select(value=medium, title=‘Select Medium’, options=uniqueMediaLst)

df_tot, nfdCount = get_dataset(df_m, medium)

tit = “NozzleOuts | NFD-Count: %d | Medium: %s.” %(nfdCount,medium)

plot = make_plot(df_tot, tit, nfdCount)

medium_select.on_change(‘value’, update)

So my make_plot function should take the updated df_tot.

The columndatasource is created inside a for-loop (inside the function make_plot):

i = 0

for (name, series) in df_tot.iteritems():

need to repmat the name to be same dimension as index

name_for_display = np.tile(name, [len(df_tot.index),1])

source = ColumnDataSource({‘x’: df_tot.index, ‘y’: series.values, ‘series_name’: name_for_display})

trouble formating x as datestring, so pre-formating and using an extra column. It’s not pretty but it works.

plot.scatter(‘x’, ‘y’, fill_alpha=0.6, size=5, source = source, color=colorRange[i])

hover = plot.select(dict(type=HoverTool))

hover.tooltips = [(“ColHead”, “@series_name”), (“Nozzle”, “@x”), (“Drops”, “@y”)]

hover.mode = ‘mouse’

i +=1

For now updating the title works, the nfdcount is also updated but every selection gives a different count and the scatterplot is not updated.

I look forward to your reply,

Best wishes,

Rakesh

···

On Wednesday, March 23, 2016 at 4:52:07 PM UTC+1, Bryan Van de ven wrote:

Hi Rakesh,

While I want to be able to help as many people as possible have a good experience with Bokeh, rewriting code at this scale is simply not something I have the time or bandwidth to do, unfortunately. Others might be able and willing to offer support at the level, perhaps. In any case the “IMDB” server example does filtering from dataframes, hopefully it can serve as a useful reference.

example: http://demo.bokehplots.com/apps/movies

code: https://github.com/bokeh/bokeh/tree/master/examples/app/movies

Thanks,

Bryan

On Mar 23, 2016, at 6:38 AM, [email protected] wrote:

Dear Bryan,

Thank you for your quick reply.

Actually I was aware CustomJS only reads JS, but I wrote it up like to clarify what I want to do: 1. updating a dataframe and 2. the plot After selection of something (in my case ‘medium’).

I have large data and ‘medium’ can be quite a long list. Moreover my columndataSource and figure p are updated inside a for-loop to be able to plot all columns from the df (with index = x-axis and columnName = legend item)
I can’t move the callback function and dropdown box inside the for-loop either, because then I could do the filtering by JS. Or do I miss anything?

The only remaining option I could try would then be to use a server as you said.

Could you maybe rewrite this code for me to understand where to start? That would be really helpful since I feel kind of stuck now.

Best wishes,

Rakesh

On Tuesday, March 22, 2016 at 4:22:34 PM UTC+1, Bryan Van de ven wrote:

I should add: it also may be possible to do the filtering in the browser, using only JavaScript. If your data is not large and there are not many filter options, you could pre-filter and send all the possible combinations into the browser as separate column data sources, then the CustomJS call back can just switch between them. Or possibly actually writing JavaScript to do the filtering by hand, it’s hard to say more without more details. The point is there is no access to pandas or numpy or anything like that in the browser.

Bryan

On Mar 22, 2016, at 10:18 AM, Bryan Van de Ven [email protected] wrote:

Hi,

There is an important point to clarify: namely that:

    CustomJS callbacks *CANNOT EXECUTE REAL PYTHON CODE*

They are JavaScript, and execute only in the browser. Even if they are written using “CustomJS.from_py_func”, all that does is proiide a convenient way to compile python into JavaScript. In the end, there is still only JavaScript executing, and only in the browser.

If you need to run actual python code in response to some user interaction (a widget or plot selection, say) then you will have to create a Bokeh Application that is run and hosted on a Bokeh server.

Bryan

On Mar 22, 2016, at 10:10 AM, [email protected] wrote:

Dear Bokeh community,

From a drop down selection I would like to have a plot updated for what has been selected.
This means a dataFrame has to be filtered first.

I am quite new to bokeh and callbacks.

For now I have:

“”"
import bokeh
from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file
from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool
from bokeh.models.widgets import Select
from bokeh.io import hplot

print(“Bokeh version: %s” %bokeh.version)
print(“Panda version: %s” %pd.version)

output_notebook()

output_file(“NozzleOut.html”)

_tools_to_show = ‘box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap’

def callbackMedium(uniqueMediaLst, df_m):
#data
medium = cb_obj.get(‘value’)
df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)
df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)

#plot
p = figure(plot_width=600,
plot_height=600,
tools=_tools_to_show,
title=“NozzleOuts. NFD-Count: %s. Medium: %s” %(nfdCount, medium) ,
y_range=Range1d(start=0.0, end=nfdCount+100))
p.xaxis.axis_label = ‘zPos[dotNr]’
p.xaxis.major_label_orientation = 90
p.yaxis.axis_label = ‘Drops[#]’

i = 0
for (name, series) in df_tot.iteritems():
# need to repmat the name to be same dimension as index
name_for_display = np.tile(name, [len(df_tot.index),1])

   source = ColumnDataSource({'x': df_tot.index, 'y': series.values, 'series_name': name_for_display})
   # trouble formating x as datestring, so pre-formating and using an extra column. It's not pretty but it works.

   p.scatter('x', 'y', fill_alpha=0.6, size=5, source = source, color=colorRange[i])    

   hover = p.select(dict(type=HoverTool))
   hover.tooltips = [("ColHead", "@series_name"), ("Nozzle", "@x"), ("Drops", "@y")]
   hover.mode = 'mouse'

   i +=1

return p

select = Select(title=“Select Medium:”, value=“All”, options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))

show(hplot(p, select))
“”"

Explanation:
A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.

Question:
I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?


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/4c4120c7-f008-4887-97b0-6d5aa3af0194%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/303496b7-4a95-4517-b0bf-0df48e8dfbf9%40continuum.io.

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

“I should add: it also may be possible to do the filtering in the browser, using only JavaScript. If your data is not large and there are not many filter options, you could pre-filter and send all the possible combinations into the browser as separate column data sources”

Bryan,

Is it possible to save multiple column data sources as separate files? It is easy to save as individual HTML files, but I can’t find how to save as column data sources.

Thank you,

William

···

On Friday, March 25, 2016 at 8:39:55 AM UTC-4, Raki wrote:

Dear Bryan,

I almost got it to work on my dashboard. I use the ‘weather’ example from ‘url=https://github.com/bokeh/bokeh/tree/master/examples/app/weather

The only remaining question I have is if the update function can be used to update a DataFrame instead of a ColumnDataSource?? Like:

def update(attrname, old, new):

global nfdCount

medium = medium_select.value

tit = “NFD-Count: %d | Medium: %s.” %(nfdCount,medium)

plot.title = tit

df_tot, nfdCount = get_dataset(df_m, medium)

df_tot.update(df_tot)

set up initial data

medium = FnameAll

medium_select = Select(value=medium, title=‘Select Medium’, options=uniqueMediaLst)

df_tot, nfdCount = get_dataset(df_m, medium)

tit = “NozzleOuts | NFD-Count: %d | Medium: %s.” %(nfdCount,medium)

plot = make_plot(df_tot, tit, nfdCount)

medium_select.on_change(‘value’, update)

So my make_plot function should take the updated df_tot.

The columndatasource is created inside a for-loop (inside the function make_plot):

i = 0

for (name, series) in df_tot.iteritems():

need to repmat the name to be same dimension as index

name_for_display = np.tile(name, [len(df_tot.index),1])

source = ColumnDataSource({‘x’: df_tot.index, ‘y’: series.values, ‘series_name’: name_for_display})

trouble formating x as datestring, so pre-formating and using an extra column. It’s not pretty but it works.

plot.scatter(‘x’, ‘y’, fill_alpha=0.6, size=5, source = source, color=colorRange[i])

hover = plot.select(dict(type=HoverTool))

hover.tooltips = [(“ColHead”, “@series_name”), (“Nozzle”, “@x”), (“Drops”, “@y”)]

hover.mode = ‘mouse’

i +=1

For now updating the title works, the nfdcount is also updated but every selection gives a different count and the scatterplot is not updated.

I look forward to your reply,

Best wishes,

Rakesh

On Wednesday, March 23, 2016 at 4:52:07 PM UTC+1, Bryan Van de ven wrote:

Hi Rakesh,

While I want to be able to help as many people as possible have a good experience with Bokeh, rewriting code at this scale is simply not something I have the time or bandwidth to do, unfortunately. Others might be able and willing to offer support at the level, perhaps. In any case the “IMDB” server example does filtering from dataframes, hopefully it can serve as a useful reference.

example: http://demo.bokehplots.com/apps/movies

code: https://github.com/bokeh/bokeh/tree/master/examples/app/movies

Thanks,

Bryan

On Mar 23, 2016, at 6:38 AM, [email protected] wrote:

Dear Bryan,

Thank you for your quick reply.

Actually I was aware CustomJS only reads JS, but I wrote it up like to clarify what I want to do: 1. updating a dataframe and 2. the plot After selection of something (in my case ‘medium’).

I have large data and ‘medium’ can be quite a long list. Moreover my columndataSource and figure p are updated inside a for-loop to be able to plot all columns from the df (with index = x-axis and columnName = legend item)
I can’t move the callback function and dropdown box inside the for-loop either, because then I could do the filtering by JS. Or do I miss anything?

The only remaining option I could try would then be to use a server as you said.

Could you maybe rewrite this code for me to understand where to start? That would be really helpful since I feel kind of stuck now.

Best wishes,

Rakesh

On Tuesday, March 22, 2016 at 4:22:34 PM UTC+1, Bryan Van de ven wrote:

I should add: it also may be possible to do the filtering in the browser, using only JavaScript. If your data is not large and there are not many filter options, you could pre-filter and send all the possible combinations into the browser as separate column data sources, then the CustomJS call back can just switch between them. Or possibly actually writing JavaScript to do the filtering by hand, it’s hard to say more without more details. The point is there is no access to pandas or numpy or anything like that in the browser.

Bryan

On Mar 22, 2016, at 10:18 AM, Bryan Van de Ven [email protected] wrote:

Hi,

There is an important point to clarify: namely that:

    CustomJS callbacks *CANNOT EXECUTE REAL PYTHON CODE*

They are JavaScript, and execute only in the browser. Even if they are written using “CustomJS.from_py_func”, all that does is proiide a convenient way to compile python into JavaScript. In the end, there is still only JavaScript executing, and only in the browser.

If you need to run actual python code in response to some user interaction (a widget or plot selection, say) then you will have to create a Bokeh Application that is run and hosted on a Bokeh server.

Bryan

On Mar 22, 2016, at 10:10 AM, [email protected] wrote:

Dear Bokeh community,

From a drop down selection I would like to have a plot updated for what has been selected.
This means a dataFrame has to be filtered first.

I am quite new to bokeh and callbacks.

For now I have:

“”"
import bokeh
from bokeh.plotting import figure, output_notebook, show, ColumnDataSource, output_file
from bokeh.models import HoverTool, BoxSelectTool, Range1d, CustomJS, TapTool
from bokeh.models.widgets import Select
from bokeh.io import hplot

print(“Bokeh version: %s” %bokeh.version)
print(“Panda version: %s” %pd.version)

output_notebook()

output_file(“NozzleOut.html”)

_tools_to_show = ‘box_zoom,pan,save,hover,resize,reset,tap,wheel_zoom,tap’

def callbackMedium(uniqueMediaLst, df_m):
#data
medium = cb_obj.get(‘value’)
df_noNan, beginDot, endDot, nfdCount, colsNozzleLogCroppedLst = NozzleOutMedium1(medium, uniqueMediaLst, df_m)
df_tot = NozzleOutMedium2(df_noNan, beginDot, endDot)

#plot
p = figure(plot_width=600,
plot_height=600,
tools=_tools_to_show,
title=“NozzleOuts. NFD-Count: %s. Medium: %s” %(nfdCount, medium) ,
y_range=Range1d(start=0.0, end=nfdCount+100))
p.xaxis.axis_label = ‘zPos[dotNr]’
p.xaxis.major_label_orientation = 90
p.yaxis.axis_label = ‘Drops[#]’

i = 0
for (name, series) in df_tot.iteritems():
# need to repmat the name to be same dimension as index
name_for_display = np.tile(name, [len(df_tot.index),1])

   source = ColumnDataSource({'x': df_tot.index, 'y': series.values, 'series_name': name_for_display})
   # trouble formating x as datestring, so pre-formating and using an extra column. It's not pretty but it works.

   p.scatter('x', 'y', fill_alpha=0.6, size=5, source = source, color=colorRange[i])    

   hover = p.select(dict(type=HoverTool))
   hover.tooltips = [("ColHead", "@series_name"), ("Nozzle", "@x"), ("Drops", "@y")]
   hover.mode = 'mouse'

   i +=1

return p

select = Select(title=“Select Medium:”, value=“All”, options=uniqueMediaLst, callback=CustomJS.from_py_func(callbackMedium))

show(hplot(p, select))
“”"

Explanation:
A medium is selected from uniqueMediaLst. Functions NozzleOutMedium1 and NozzleOutMedium2, filters df_m from the selected medium and creates df_tot (index of 388 to 2170, with 12 columns. values are ints. In the for loop each column is plotted and proper hovering is added.

Question:
I am aware that the callback function is not defined in the way it should be. What is the proper way to write the callback function so that the dataFrame is filtered and the plot p is updated with each selection?


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/4c4120c7-f008-4887-97b0-6d5aa3af0194%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/303496b7-4a95-4517-b0bf-0df48e8dfbf9%40continuum.io.

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