Plots not updating with RadioButtonGroup

Hello,

My plots are not updating with click of RadioButtonGroup. Following is the snippet:

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):

current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]

test.data = {

‘Dt’ : current.Dt,

‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),

‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),

}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())

button_group = RadioButtonGroup(labels=depkey, active=0)

button_group.on_click(radio_button_group_handler)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)

facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)

facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

Any Suggestions?

Thanks!

Is it possible to include a complete example? It's often *very* quick to diagnose a problem if the code can just be run. It's also possible there is a problem outside this snippet.

Thanks,

Bryan

···

On Jan 10, 2017, at 1:11 PM, [email protected] wrote:

Hello,

My plots are not updating with click of RadioButtonGroup. Following is the snippet:

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):
  current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
  test.data = {
        'Dt' : current.Dt,
        'Census' : current.Census.apply(lambda v: "{:.2f}".format(v)),
        'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
    }

depkey = list(totData.DepartmentProviderName[totData.FacilityName == "St. Anne's"].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')

Any Suggestions?

Thanks!

--
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/de12a880-c6c2-4a21-9a5c-c4fddb9354a9%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Sure it is :

from bokeh.io import curdoc, output_file, show, push_notebook

from bokeh.layouts import column,row,widgetbox

from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool

from bokeh.plotting import figure, reset_output

from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup

from numpy.random import random, normal, lognormal

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):

current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]

test.data = {

‘Dt’ : current.Dt,

‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),

‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),

}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())

button_group = RadioButtonGroup(labels=depkey, active=0)

button_group.on_click(radio_button_group_handler)

SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)

facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)

facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)

SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

Would this help, Bryan?

Thanks,

Pratik

···

On Tuesday, 10 January 2017 14:32:05 UTC-5, Bryan Van de ven wrote:

Is it possible to include a complete example? It’s often very quick to diagnose a problem if the code can just be run. It’s also possible there is a problem outside this snippet.

Thanks,

Bryan

On Jan 10, 2017, at 1:11 PM, [email protected] wrote:

Hello,

My plots are not updating with click of RadioButtonGroup. Following is the snippet:

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):

    current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
    test.data = {
    'Dt'           : current.Dt,
    'Census'       : current.Census.apply(lambda v: "{:.2f}".format(v)),
    'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())

button_group = RadioButtonGroup(labels=depkey, active=0)

button_group.on_click(radio_button_group_handler)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)

facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)

facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

Any Suggestions?

Thanks!


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/de12a880-c6c2-4a21-9a5c-c4fddb9354a9%40continuum.io.

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

Hi,

Almost, but not quite. I can't run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.

Thanks,

Bryan

···

On Jan 10, 2017, at 1:53 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):
  current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
  test.data = {
        'Dt' : current.Dt,
        'Census' : current.Census.apply(lambda v: "{:.2f}".format(v)),
        'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
    }

depkey = list(totData.DepartmentProviderName[totData.FacilityName == "St. Anne's"].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title='Test')

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

from bokeh.io import curdoc, output_file, show, push_notebook

from bokeh.layouts import column,row,widgetbox

from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool

from bokeh.plotting import figure, reset_output

from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup

from numpy.random import random, normal, lognormal

test = pd.DataFrame(data={‘DepartmentProviderName’:[‘Pysch1’,‘Pysch1’,‘Pysch2’,‘Pysch2’,‘Pysch3’,‘Pysch3’],‘CountAtStart’:[10,15,16,14,11,10], ‘Census’:[10,12,15,12,13,14], ‘Month’:[9,9,9,9,10,10], ‘Dt’:[‘9/27/2016 1:00:00 AM’,‘9/26/2016 1:00:00 AM’,‘9/27/2016 1:00:00 AM’,‘9/28/2016 1:00:00 AM’,‘9/29/2016 1:00:00 AM’,‘9/30/2016 1:00:00 AM’]})

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=Census=,CountAtStart=))

def radio_button_group_handler(new):

current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]

test.data = {

‘Dt’ : current.Dt,

‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),

‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),

}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())

button_group = RadioButtonGroup(labels=depkey, active=0)

button_group.on_click(radio_button_group_handler)

SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)

facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)

facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)

SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

Hi Bryan,

How about now?

···

On Tuesday, 10 January 2017 15:03:24 UTC-5, Bryan Van de ven wrote:

Hi,

Almost, but not quite. I can’t run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.

Thanks,

Bryan

On Jan 10, 2017, at 1:53 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook

from bokeh.layouts import column,row,widgetbox

from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool

from bokeh.plotting import figure, reset_output

from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup

from numpy.random import random, normal, lognormal

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):

    current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
    test.data = {
    'Dt'           : current.Dt,
    'Census'       : current.Census.apply(lambda v: "{:.2f}".format(v)),
    'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())

button_group = RadioButtonGroup(labels=depkey, active=0)

button_group.on_click(radio_button_group_handler)

SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)

facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)

facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)

SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

After making several changes, I ran the version below to get some information.

The problem I would say is with your data. You are converting everything to strings? I really doubt that's what you want or intend, and if that's the case, times need to be real datetime objects of some sort, not strings. If not, and you do want string values, you need to configure the plot ranges to be categorical:

  http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes

Thanks,

Bryan

from bokeh.io import curdoc, output_file, show, push_notebook
    from bokeh.layouts import column,row,widgetbox
    from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, LassoSelectTool
    from bokeh.plotting import figure, reset_output
    from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
    import pandas as pd
    from numpy.random import random, normal, lognormal

    data = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016 1:00:00 AM','9/26/2016 1:00:00 AM','9/27/2016 1:00:00 AM','9/28/2016 1:00:00 AM','9/29/2016 1:00:00 AM','9/30/2016 1:00:00 AM']})
    print(data)

    menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')

    test = ColumnDataSource(data=dict(Dt=, Census=,CountAtStart=))

    def radio_button_group_handler(new):
        new = ['Pysch1', 'Pysch2','Pysch3'][new]
        print(new)
        current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
        test.data = {
            'Dt' : list(current.Dt),
            'Census' : list(current.Census.apply(lambda v: "{:.2f}".format(v))),
            'CountAtStart' : list(current.CountAtStart.apply(lambda v: "{:.2f}".format(v))),
        }
        print(test.data)

    depkey = ['Pysch1', 'Pysch2','Pysch3']
    button_group = RadioButtonGroup(labels=depkey, active=0)
    button_group.on_click(radio_button_group_handler)
    SAHbutton = widgetbox(button_group, width = 500)

    facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
    facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
    facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')

    l1 = column(SAHbutton, facdept_plot)
    SAHtab = Panel(child = l1, title='Test')

    layout = Tabs(tabs = [SAHtab], width = 500)

    final_layout = row(menu,layout)

    curdoc().add_root(final_layout)

···

On Jan 10, 2017, at 2:20 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

test = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016 1:00:00 AM','9/26/2016 1:00:00 AM','9/27/2016 1:00:00 AM','9/28/2016 1:00:00 AM','9/29/2016 1:00:00 AM','9/30/2016 1:00:00 AM']})

menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')

test = ColumnDataSource(data=dict(Dt=Census=,CountAtStart=))

def radio_button_group_handler(new):
  current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
  test.data = {
        'Dt' : current.Dt,
        'Census' : current.Census.apply(lambda v: "{:.2f}".format(v)),
        'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
    }

depkey = list(totData.DepartmentProviderName[totData.FacilityName == "St. Anne's"].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title='Test')

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

Hi Bryan,

How about now?

On Tuesday, 10 January 2017 15:03:24 UTC-5, Bryan Van de ven wrote:
Hi,

Almost, but not quite. I can't run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.

Thanks,

Bryan

> On Jan 10, 2017, at 1:53 PM, [email protected] wrote:
>
> from bokeh.io import curdoc, output_file, show, push_notebook
> from bokeh.layouts import column,row,widgetbox
> from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
> from bokeh.plotting import figure, reset_output
> from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
> from numpy.random import random, normal, lognormal
>
> menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')
>
> test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))
>
> def radio_button_group_handler(new):
> current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
> test.data = {
> 'Dt' : current.Dt,
> 'Census' : current.Census.apply(lambda v: "{:.2f}".format(v)),
> 'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
> }
>
> depkey = list(totData.DepartmentProviderName[totData.FacilityName == "St. Anne's"].unique())
> button_group = RadioButtonGroup(labels=depkey, active=0)
> button_group.on_click(radio_button_group_handler)
> SAHbutton = widgetbox(button_group, width = 500)
>
> facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
> facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
> facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')
>
> l1 = column(SAHbutton, facdept_plot)
> SAHtab = Panel(child = l1, title='Test')
>
> layout = Tabs(tabs = [SAHtab], width = 500)
>
> final_layout = row(menu,layout)
>
> curdoc().add_root(final_layout)
>

--
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/3d718896-634b-44e9-99d8-477cb0672e48%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Well, I appreciate your reply Bryan - but I am able to generate plots with the datatype I have. Do you think the other logic I have used is fine, meaning the RadioButtonGroup and the callback function?

Also, how and where can I see the printed objects? I am assuming in the command window, correct? If yes I am not able to apparently! Do you example snippet for that?

I did try this from one of your suggestions, but this did not work on server

Thanks

Pratik

···

On Tuesday, 10 January 2017 15:35:44 UTC-5, Bryan Van de ven wrote:

After making several changes, I ran the version below to get some information.

The problem I would say is with your data. You are converting everything to strings? I really doubt that’s what you want or intend, and if that’s the case, times need to be real datetime objects of some sort, not strings. If not, and you do want string values, you need to configure the plot ranges to be categorical:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes)

Thanks,

Bryan

from bokeh.io import curdoc, output_file, show, push_notebook

from bokeh.layouts import column,row,widgetbox

from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, LassoSelectTool

from bokeh.plotting import figure, reset_output

from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup

import pandas as pd

from numpy.random import random, normal, lognormal



data = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016  1:00:00 AM','9/26/2016  1:00:00 AM','9/27/2016  1:00:00 AM','9/28/2016  1:00:00 AM','9/29/2016  1:00:00 AM','9/30/2016  1:00:00 AM']})

print(data)



menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')



test = ColumnDataSource(data=dict(Dt=[], Census=[],CountAtStart=[]))



def radio_button_group_handler(new):

    new = ['Pysch1', 'Pysch2','Pysch3'][new]

    print(new)

    current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]

    test.data = {

        'Dt'           : list(current.Dt),

        'Census'       : list(current.Census.apply(lambda v: "{:.2f}".format(v))),

        'CountAtStart' : list(current.CountAtStart.apply(lambda v: "{:.2f}".format(v))),

    }

    print(test.data)



depkey = ['Pysch1', 'Pysch2','Pysch3']

button_group = RadioButtonGroup(labels=depkey, active=0)

button_group.on_click(radio_button_group_handler)

SAHbutton = widgetbox(button_group, width = 500)



facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')

facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')

facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')



l1 = column(SAHbutton, facdept_plot)

SAHtab = Panel(child = l1, title='Test')



layout = Tabs(tabs = [SAHtab], width = 500)



final_layout = row(menu,layout)



curdoc().add_root(final_layout)

On Jan 10, 2017, at 2:20 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook

from bokeh.layouts import column,row,widgetbox

from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool

from bokeh.plotting import figure, reset_output

from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup

from numpy.random import random, normal, lognormal

test = pd.DataFrame(data={‘DepartmentProviderName’:[‘Pysch1’,‘Pysch1’,‘Pysch2’,‘Pysch2’,‘Pysch3’,‘Pysch3’],‘CountAtStart’:[10,15,16,14,11,10], ‘Census’:[10,12,15,12,13,14], ‘Month’:[9,9,9,9,10,10], ‘Dt’:[‘9/27/2016 1:00:00 AM’,‘9/26/2016 1:00:00 AM’,‘9/27/2016 1:00:00 AM’,‘9/28/2016 1:00:00 AM’,‘9/29/2016 1:00:00 AM’,‘9/30/2016 1:00:00 AM’]})

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=Census=,CountAtStart=))

def radio_button_group_handler(new):

    current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
    test.data = {
    'Dt'           : current.Dt,
    'Census'       : current.Census.apply(lambda v: "{:.2f}".format(v)),
    'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())

button_group = RadioButtonGroup(labels=depkey, active=0)

button_group.on_click(radio_button_group_handler)

SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)

facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)

facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)

SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

Hi Bryan,

How about now?

On Tuesday, 10 January 2017 15:03:24 UTC-5, Bryan Van de ven wrote:

Hi,

Almost, but not quite. I can’t run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.

Thanks,

Bryan

On Jan 10, 2017, at 1:53 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):
current = data[(data.DepartmentProviderName == “%s” % new) & (data.Month == 9)]
test.data = {
‘Dt’ : current.Dt,
‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),
‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)
facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)
facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)


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/3d718896-634b-44e9-99d8-477cb0672e48%40continuum.io.

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

Hi,

Sometimes it's good to take a step back and break up a problem into smaller pieces. First, a few comments:

* You can put any print statements you like in the app, in the callbacks, etc. They will show in the console where you run the server

* I'd suggest looking in the docs gallery for other time series examples, and getting the plot to work all by itself, without the server, first

Lastly, here is a complete but much simpler example that uses a radio button to update a plot, that you can run and study, in case it is instructive:

    from bokeh.io import curdoc, output_file
    from bokeh.layouts import column
    from bokeh.models import ColumnDataSource, RadioButtonGroup
    from bokeh.plotting import figure
    from bokeh.sampledata.iris import flowers

    species = ['setosa', 'versicolor', 'virginica']

    def update_data(species):
        subset = flowers[flowers.species==species]
        return dict(
            sepal_width=subset.sepal_width,
            sepal_length=subset.sepal_length,
        )

    source = ColumnDataSource()
    source.data = update_data('setosa')

    def callback(new):
        source.data = update_data(species[new])

    button_group = RadioButtonGroup(labels=species, active=0)
    button_group.on_click(callback)

    plot = figure()
    plot.circle(x='sepal_width', y='sepal_length', source=source)

    curdoc().add_root(column(button_group, plot))

Thanks,

Bryan

···

On Jan 10, 2017, at 2:44 PM, [email protected] wrote:

Well, I appreciate your reply Bryan - but I am able to generate plots with the datatype I have. Do you think the other logic I have used is fine, meaning the RadioButtonGroup and the callback function?

Also, how and where can I see the printed objects? I am assuming in the command window, correct? If yes I am not able to apparently! Do you example snippet for that?

I did try this from one of your suggestions, but this did not work on server

Thanks
Pratik

On Tuesday, 10 January 2017 15:35:44 UTC-5, Bryan Van de ven wrote:
After making several changes, I ran the version below to get some information.

The problem I would say is with your data. You are converting everything to strings? I really doubt that's what you want or intend, and if that's the case, times need to be real datetime objects of some sort, not strings. If not, and you do want string values, you need to configure the plot ranges to be categorical:

        http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes

Thanks,

Bryan

from bokeh.io import curdoc, output_file, show, push_notebook
    from bokeh.layouts import column,row,widgetbox
    from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, LassoSelectTool
    from bokeh.plotting import figure, reset_output
    from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
    import pandas as pd
    from numpy.random import random, normal, lognormal

    data = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016 1:00:00 AM','9/26/2016 1:00:00 AM','9/27/2016 1:00:00 AM','9/28/2016 1:00:00 AM','9/29/2016 1:00:00 AM','9/30/2016 1:00:00 AM']})
    print(data)

    menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')

    test = ColumnDataSource(data=dict(Dt=, Census=,CountAtStart=))

    def radio_button_group_handler(new):
        new = ['Pysch1', 'Pysch2','Pysch3'][new]
        print(new)
        current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
        test.data = {
            'Dt' : list(current.Dt),
            'Census' : list(current.Census.apply(lambda v: "{:.2f}".format(v))),
            'CountAtStart' : list(current.CountAtStart.apply(lambda v: "{:.2f}".format(v))),
        }
        print(test.data)

    depkey = ['Pysch1', 'Pysch2','Pysch3']
    button_group = RadioButtonGroup(labels=depkey, active=0)
    button_group.on_click(radio_button_group_handler)
    SAHbutton = widgetbox(button_group, width = 500)

    facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
    facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
    facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')

    l1 = column(SAHbutton, facdept_plot)
    SAHtab = Panel(child = l1, title='Test')

    layout = Tabs(tabs = [SAHtab], width = 500)

    final_layout = row(menu,layout)

    curdoc().add_root(final_layout)

> On Jan 10, 2017, at 2:20 PM, [email protected] wrote:
>
> from bokeh.io import curdoc, output_file, show, push_notebook
> from bokeh.layouts import column,row,widgetbox
> from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
> from bokeh.plotting import figure, reset_output
> from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
> from numpy.random import random, normal, lognormal
>
> test = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016 1:00:00 AM','9/26/2016 1:00:00 AM','9/27/2016 1:00:00 AM','9/28/2016 1:00:00 AM','9/29/2016 1:00:00 AM','9/30/2016 1:00:00 AM']})
>
> menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')
>
> test = ColumnDataSource(data=dict(Dt=Census=,CountAtStart=))
>
> def radio_button_group_handler(new):
> current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
> test.data = {
> 'Dt' : current.Dt,
> 'Census' : current.Census.apply(lambda v: "{:.2f}".format(v)),
> 'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
> }
>
> depkey = list(totData.DepartmentProviderName[totData.FacilityName == "St. Anne's"].unique())
> button_group = RadioButtonGroup(labels=depkey, active=0)
> button_group.on_click(radio_button_group_handler)
> SAHbutton = widgetbox(button_group, width = 500)
>
> facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
> facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
> facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')
>
> l1 = column(SAHbutton, facdept_plot)
> SAHtab = Panel(child = l1, title='Test')
>
> layout = Tabs(tabs = [SAHtab], width = 500)
>
> final_layout = row(menu,layout)
>
> curdoc().add_root(final_layout)
>
>
> Hi Bryan,
>
> How about now?
>
> On Tuesday, 10 January 2017 15:03:24 UTC-5, Bryan Van de ven wrote:
> Hi,
>
> Almost, but not quite. I can't run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.
>
> Thanks,
>
> Bryan
>
> > On Jan 10, 2017, at 1:53 PM, [email protected] wrote:
> >
> > from bokeh.io import curdoc, output_file, show, push_notebook
> > from bokeh.layouts import column,row,widgetbox
> > from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
> > from bokeh.plotting import figure, reset_output
> > from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
> > from numpy.random import random, normal, lognormal
> >
> > menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')
> >
> > test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))
> >
> > def radio_button_group_handler(new):
> > current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
> > test.data = {
> > 'Dt' : current.Dt,
> > 'Census' : current.Census.apply(lambda v: "{:.2f}".format(v)),
> > 'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
> > }
> >
> > depkey = list(totData.DepartmentProviderName[totData.FacilityName == "St. Anne's"].unique())
> > button_group = RadioButtonGroup(labels=depkey, active=0)
> > button_group.on_click(radio_button_group_handler)
> > SAHbutton = widgetbox(button_group, width = 500)
> >
> > facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
> > facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
> > facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')
> >
> > l1 = column(SAHbutton, facdept_plot)
> > SAHtab = Panel(child = l1, title='Test')
> >
> > layout = Tabs(tabs = [SAHtab], width = 500)
> >
> > final_layout = row(menu,layout)
> >
> > curdoc().add_root(final_layout)
> >
>
>
> --
> 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/3d718896-634b-44e9-99d8-477cb0672e48%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/c0c9de54-32b4-49a9-8b2f-464845f27970%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,

Thank you for this example. I think this will help and I will definitely try to see the time series examples.

Thank you for your so quick responses. Really appreciate the support, especially what you are providing.

Thanks,

Pratik

···

On Tuesday, 10 January 2017 15:47:39 UTC-5, Bryan Van de ven wrote:

Hi,

Sometimes it’s good to take a step back and break up a problem into smaller pieces. First, a few comments:

  • You can put any print statements you like in the app, in the callbacks, etc. They will show in the console where you run the server

  • I’d suggest looking in the docs gallery for other time series examples, and getting the plot to work all by itself, without the server, first

Lastly, here is a complete but much simpler example that uses a radio button to update a plot, that you can run and study, in case it is instructive:

from [bokeh.io](http://bokeh.io) import curdoc, output_file

from bokeh.layouts import column

from bokeh.models import ColumnDataSource, RadioButtonGroup

from bokeh.plotting import figure

from bokeh.sampledata.iris import flowers



species = ['setosa', 'versicolor', 'virginica']



def update_data(species):

    subset = flowers[flowers.species==species]

    return dict(

        sepal_width=subset.sepal_width,

        sepal_length=subset.sepal_length,

    )



source = ColumnDataSource()
source.data = update_data('setosa')



def callback(new):

    source.data = update_data(species[new])



button_group = RadioButtonGroup(labels=species, active=0)

button_group.on_click(callback)



plot = figure()

plot.circle(x='sepal_width', y='sepal_length', source=source)



curdoc().add_root(column(button_group, plot))

Thanks,

Bryan

On Jan 10, 2017, at 2:44 PM, [email protected] wrote:

Well, I appreciate your reply Bryan - but I am able to generate plots with the datatype I have. Do you think the other logic I have used is fine, meaning the RadioButtonGroup and the callback function?

Also, how and where can I see the printed objects? I am assuming in the command window, correct? If yes I am not able to apparently! Do you example snippet for that?

I did try this from one of your suggestions, but this did not work on server

Thanks

Pratik

On Tuesday, 10 January 2017 15:35:44 UTC-5, Bryan Van de ven wrote:

After making several changes, I ran the version below to get some information.

The problem I would say is with your data. You are converting everything to strings? I really doubt that’s what you want or intend, and if that’s the case, times need to be real datetime objects of some sort, not strings. If not, and you do want string values, you need to configure the plot ranges to be categorical:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes)

Thanks,

Bryan

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
import pandas as pd
from numpy.random import random, normal, lognormal

data = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016  1:00:00 AM','9/26/2016  1:00:00 AM','9/27/2016  1:00:00 AM','9/28/2016  1:00:00 AM','9/29/2016  1:00:00 AM','9/30/2016  1:00:00 AM']})
print(data)

menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')

test = ColumnDataSource(data=dict(Dt=[], Census=[],CountAtStart=[]))

def radio_button_group_handler(new):
    new = ['Pysch1', 'Pysch2','Pysch3'][new]
    print(new)
    current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
    test.data = {
        'Dt'           : list(current.Dt),
        'Census'       : list(current.Census.apply(lambda v: "{:.2f}".format(v))),
        'CountAtStart' : list(current.CountAtStart.apply(lambda v: "{:.2f}".format(v))),
    }
    print(test.data)

depkey = ['Pysch1', 'Pysch2','Pysch3']
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title='Test')

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

On Jan 10, 2017, at 2:20 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

test = pd.DataFrame(data={‘DepartmentProviderName’:[‘Pysch1’,‘Pysch1’,‘Pysch2’,‘Pysch2’,‘Pysch3’,‘Pysch3’],‘CountAtStart’:[10,15,16,14,11,10], ‘Census’:[10,12,15,12,13,14], ‘Month’:[9,9,9,9,10,10], ‘Dt’:[‘9/27/2016 1:00:00 AM’,‘9/26/2016 1:00:00 AM’,‘9/27/2016 1:00:00 AM’,‘9/28/2016 1:00:00 AM’,‘9/29/2016 1:00:00 AM’,‘9/30/2016 1:00:00 AM’]})

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=Census=,CountAtStart=))

def radio_button_group_handler(new):
current = data[(data.DepartmentProviderName == “%s” % new) & (data.Month == 9)]
test.data = {
‘Dt’ : current.Dt,
‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),
‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)
facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)
facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

Hi Bryan,

How about now?

On Tuesday, 10 January 2017 15:03:24 UTC-5, Bryan Van de ven wrote:
Hi,

Almost, but not quite. I can’t run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.

Thanks,

Bryan

On Jan 10, 2017, at 1:53 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):
current = data[(data.DepartmentProviderName == “%s” % new) & (data.Month == 9)]
test.data = {
‘Dt’ : current.Dt,
‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),
‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)
facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)
facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)


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/3d718896-634b-44e9-99d8-477cb0672e48%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/c0c9de54-32b4-49a9-8b2f-464845f27970%40continuum.io.

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

Hi Bryan

Can you explain what this piece of code is doing here:

source.data = update_data(species[new])

Thanks,

Pratik

···

On Tuesday, 10 January 2017 16:27:14 UTC-5, [email protected] wrote:

Hi Bryan,

Thank you for this example. I think this will help and I will definitely try to see the time series examples.

Thank you for your so quick responses. Really appreciate the support, especially what you are providing.

Thanks,

Pratik

On Tuesday, 10 January 2017 15:47:39 UTC-5, Bryan Van de ven wrote:

Hi,

Sometimes it’s good to take a step back and break up a problem into smaller pieces. First, a few comments:

  • You can put any print statements you like in the app, in the callbacks, etc. They will show in the console where you run the server

  • I’d suggest looking in the docs gallery for other time series examples, and getting the plot to work all by itself, without the server, first

Lastly, here is a complete but much simpler example that uses a radio button to update a plot, that you can run and study, in case it is instructive:

from [bokeh.io](http://bokeh.io) import curdoc, output_file

from bokeh.layouts import column

from bokeh.models import ColumnDataSource, RadioButtonGroup

from bokeh.plotting import figure

from bokeh.sampledata.iris import flowers



species = ['setosa', 'versicolor', 'virginica']



def update_data(species):

    subset = flowers[flowers.species==species]

    return dict(

        sepal_width=subset.sepal_width,

        sepal_length=subset.sepal_length,

    )



source = ColumnDataSource()
source.data = update_data('setosa')



def callback(new):

    source.data = update_data(species[new])



button_group = RadioButtonGroup(labels=species, active=0)

button_group.on_click(callback)



plot = figure()

plot.circle(x='sepal_width', y='sepal_length', source=source)



curdoc().add_root(column(button_group, plot))

Thanks,

Bryan

On Jan 10, 2017, at 2:44 PM, [email protected] wrote:

Well, I appreciate your reply Bryan - but I am able to generate plots with the datatype I have. Do you think the other logic I have used is fine, meaning the RadioButtonGroup and the callback function?

Also, how and where can I see the printed objects? I am assuming in the command window, correct? If yes I am not able to apparently! Do you example snippet for that?

I did try this from one of your suggestions, but this did not work on server

Thanks

Pratik

On Tuesday, 10 January 2017 15:35:44 UTC-5, Bryan Van de ven wrote:

After making several changes, I ran the version below to get some information.

The problem I would say is with your data. You are converting everything to strings? I really doubt that’s what you want or intend, and if that’s the case, times need to be real datetime objects of some sort, not strings. If not, and you do want string values, you need to configure the plot ranges to be categorical:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes)

Thanks,

Bryan

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
import pandas as pd
from numpy.random import random, normal, lognormal

data = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016  1:00:00 AM','9/26/2016  1:00:00 AM','9/27/2016  1:00:00 AM','9/28/2016  1:00:00 AM','9/29/2016  1:00:00 AM','9/30/2016  1:00:00 AM']})
print(data)

menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')

test = ColumnDataSource(data=dict(Dt=[], Census=[],CountAtStart=[]))

def radio_button_group_handler(new):
    new = ['Pysch1', 'Pysch2','Pysch3'][new]
    print(new)
    current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
    test.data = {
        'Dt'           : list(current.Dt),
        'Census'       : list(current.Census.apply(lambda v: "{:.2f}".format(v))),
        'CountAtStart' : list(current.CountAtStart.apply(lambda v: "{:.2f}".format(v))),
    }
    print(test.data)

depkey = ['Pysch1', 'Pysch2','Pysch3']
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title='Test')

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

On Jan 10, 2017, at 2:20 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

test = pd.DataFrame(data={‘DepartmentProviderName’:[‘Pysch1’,‘Pysch1’,‘Pysch2’,‘Pysch2’,‘Pysch3’,‘Pysch3’],‘CountAtStart’:[10,15,16,14,11,10], ‘Census’:[10,12,15,12,13,14], ‘Month’:[9,9,9,9,10,10], ‘Dt’:[‘9/27/2016 1:00:00 AM’,‘9/26/2016 1:00:00 AM’,‘9/27/2016 1:00:00 AM’,‘9/28/2016 1:00:00 AM’,‘9/29/2016 1:00:00 AM’,‘9/30/2016 1:00:00 AM’]})

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=Census=,CountAtStart=))

def radio_button_group_handler(new):
current = data[(data.DepartmentProviderName == “%s” % new) & (data.Month == 9)]
test.data = {
‘Dt’ : current.Dt,
‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),
‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)
facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)
facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

Hi Bryan,

How about now?

On Tuesday, 10 January 2017 15:03:24 UTC-5, Bryan Van de ven wrote:
Hi,

Almost, but not quite. I can’t run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.

Thanks,

Bryan

On Jan 10, 2017, at 1:53 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):
current = data[(data.DepartmentProviderName == “%s” % new) & (data.Month == 9)]
test.data = {
‘Dt’ : current.Dt,
‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),
‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)
facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)
facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)


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/3d718896-634b-44e9-99d8-477cb0672e48%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/c0c9de54-32b4-49a9-8b2f-464845f27970%40continuum.io.

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

Hi, sure:

* "new" is the integer index of the newly selected button
* species is the list of the button labels (e.g. "setosa")
* so species[new] is the actual species name corresponding to a selected button

* update_data takes a species name and returns a dict of data for just that species

So all together:

   source.data = update_data(species[new])

gets a new dict of data for the species corresponding to the pushed button, and sets source.data to it (which causes the plot to update)

Thanks,

Bryan

···

On Jan 10, 2017, at 8:02 PM, [email protected] wrote:

Hi Bryan

Can you explain what this piece of code is doing here:

source.data = update_data(species[new])

Thanks,
Pratik

On Tuesday, 10 January 2017 16:27:14 UTC-5, [email protected] wrote:
Hi Bryan,

Thank you for this example. I think this will help and I will definitely try to see the time series examples.

Thank you for your so quick responses. Really appreciate the support, especially what you are providing.

Thanks,
Pratik

On Tuesday, 10 January 2017 15:47:39 UTC-5, Bryan Van de ven wrote:
Hi,

Sometimes it's good to take a step back and break up a problem into smaller pieces. First, a few comments:

* You can put any print statements you like in the app, in the callbacks, etc. They will show in the console where you run the server

* I'd suggest looking in the docs gallery for other time series examples, and getting the plot to work all by itself, without the server, first

Lastly, here is a complete but much simpler example that uses a radio button to update a plot, that you can run and study, in case it is instructive:

    from bokeh.io import curdoc, output_file
    from bokeh.layouts import column
    from bokeh.models import ColumnDataSource, RadioButtonGroup
    from bokeh.plotting import figure
    from bokeh.sampledata.iris import flowers

    species = ['setosa', 'versicolor', 'virginica']

    def update_data(species):
        subset = flowers[flowers.species==species]
        return dict(
            sepal_width=subset.sepal_width,
            sepal_length=subset.sepal_length,
        )

    source = ColumnDataSource()
    source.data = update_data('setosa')

    def callback(new):
        source.data = update_data(species[new])

    button_group = RadioButtonGroup(labels=species, active=0)
    button_group.on_click(callback)

    plot = figure()
    plot.circle(x='sepal_width', y='sepal_length', source=source)

    curdoc().add_root(column(button_group, plot))

Thanks,

Bryan

> On Jan 10, 2017, at 2:44 PM, [email protected] wrote:
>
> Well, I appreciate your reply Bryan - but I am able to generate plots with the datatype I have. Do you think the other logic I have used is fine, meaning the RadioButtonGroup and the callback function?
>
> Also, how and where can I see the printed objects? I am assuming in the command window, correct? If yes I am not able to apparently! Do you example snippet for that?
>
> I did try this from one of your suggestions, but this did not work on server
>
> Thanks
> Pratik
>
>
> On Tuesday, 10 January 2017 15:35:44 UTC-5, Bryan Van de ven wrote:
> After making several changes, I ran the version below to get some information.
>
> The problem I would say is with your data. You are converting everything to strings? I really doubt that's what you want or intend, and if that's the case, times need to be real datetime objects of some sort, not strings. If not, and you do want string values, you need to configure the plot ranges to be categorical:
>
> http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes
>
> Thanks,
>
> Bryan
>
> from bokeh.io import curdoc, output_file, show, push_notebook
> from bokeh.layouts import column,row,widgetbox
> from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, LassoSelectTool
> from bokeh.plotting import figure, reset_output
> from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
> import pandas as pd
> from numpy.random import random, normal, lognormal
>
> data = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016 1:00:00 AM','9/26/2016 1:00:00 AM','9/27/2016 1:00:00 AM','9/28/2016 1:00:00 AM','9/29/2016 1:00:00 AM','9/30/2016 1:00:00 AM']})
> print(data)
>
> menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')
>
> test = ColumnDataSource(data=dict(Dt=, Census=,CountAtStart=))
>
> def radio_button_group_handler(new):
> new = ['Pysch1', 'Pysch2','Pysch3'][new]
> print(new)
> current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
> test.data = {
> 'Dt' : list(current.Dt),
> 'Census' : list(current.Census.apply(lambda v: "{:.2f}".format(v))),
> 'CountAtStart' : list(current.CountAtStart.apply(lambda v: "{:.2f}".format(v))),
> }
> print(test.data)
>
> depkey = ['Pysch1', 'Pysch2','Pysch3']
> button_group = RadioButtonGroup(labels=depkey, active=0)
> button_group.on_click(radio_button_group_handler)
> SAHbutton = widgetbox(button_group, width = 500)
>
> facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
> facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
> facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')
>
> l1 = column(SAHbutton, facdept_plot)
> SAHtab = Panel(child = l1, title='Test')
>
> layout = Tabs(tabs = [SAHtab], width = 500)
>
> final_layout = row(menu,layout)
>
> curdoc().add_root(final_layout)
>
>
> > On Jan 10, 2017, at 2:20 PM, [email protected] wrote:
> >
> > from bokeh.io import curdoc, output_file, show, push_notebook
> > from bokeh.layouts import column,row,widgetbox
> > from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
> > from bokeh.plotting import figure, reset_output
> > from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
> > from numpy.random import random, normal, lognormal
> >
> > test = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016 1:00:00 AM','9/26/2016 1:00:00 AM','9/27/2016 1:00:00 AM','9/28/2016 1:00:00 AM','9/29/2016 1:00:00 AM','9/30/2016 1:00:00 AM']})
> >
> > menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')
> >
> > test = ColumnDataSource(data=dict(Dt=Census=,CountAtStart=))
> >
> > def radio_button_group_handler(new):
> > current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
> > test.data = {
> > 'Dt' : current.Dt,
> > 'Census' : current.Census.apply(lambda v: "{:.2f}".format(v)),
> > 'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
> > }
> >
> > depkey = list(totData.DepartmentProviderName[totData.FacilityName == "St. Anne's"].unique())
> > button_group = RadioButtonGroup(labels=depkey, active=0)
> > button_group.on_click(radio_button_group_handler)
> > SAHbutton = widgetbox(button_group, width = 500)
> >
> > facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
> > facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
> > facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')
> >
> > l1 = column(SAHbutton, facdept_plot)
> > SAHtab = Panel(child = l1, title='Test')
> >
> > layout = Tabs(tabs = [SAHtab], width = 500)
> >
> > final_layout = row(menu,layout)
> >
> > curdoc().add_root(final_layout)
> >
> >
> > Hi Bryan,
> >
> > How about now?
> >
> > On Tuesday, 10 January 2017 15:03:24 UTC-5, Bryan Van de ven wrote:
> > Hi,
> >
> > Almost, but not quite. I can't run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.
> >
> > Thanks,
> >
> > Bryan
> >
> > > On Jan 10, 2017, at 1:53 PM, [email protected] wrote:
> > >
> > > from bokeh.io import curdoc, output_file, show, push_notebook
> > > from bokeh.layouts import column,row,widgetbox
> > > from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
> > > from bokeh.plotting import figure, reset_output
> > > from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
> > > from numpy.random import random, normal, lognormal
> > >
> > > menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')
> > >
> > > test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))
> > >
> > > def radio_button_group_handler(new):
> > > current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
> > > test.data = {
> > > 'Dt' : current.Dt,
> > > 'Census' : current.Census.apply(lambda v: "{:.2f}".format(v)),
> > > 'CountAtStart' : current.CountAtStart.apply(lambda v: "{:.2f}".format(v)),
> > > }
> > >
> > > depkey = list(totData.DepartmentProviderName[totData.FacilityName == "St. Anne's"].unique())
> > > button_group = RadioButtonGroup(labels=depkey, active=0)
> > > button_group.on_click(radio_button_group_handler)
> > > SAHbutton = widgetbox(button_group, width = 500)
> > >
> > > facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
> > > facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
> > > facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')
> > >
> > > l1 = column(SAHbutton, facdept_plot)
> > > SAHtab = Panel(child = l1, title='Test')
> > >
> > > layout = Tabs(tabs = [SAHtab], width = 500)
> > >
> > > final_layout = row(menu,layout)
> > >
> > > curdoc().add_root(final_layout)
> > >
> >
> >
> > --
> > 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/3d718896-634b-44e9-99d8-477cb0672e48%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/c0c9de54-32b4-49a9-8b2f-464845f27970%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/d20037f7-bcb5-45b9-bd2e-fe9d3ec5eeef%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Gotcha!

Thanks, Bryan!

···

On Wednesday, 11 January 2017 10:06:50 UTC-5, Bryan Van de ven wrote:

Hi, sure:

  • “new” is the integer index of the newly selected button

  • species is the list of the button labels (e.g. “setosa”)

  • so species[new] is the actual species name corresponding to a selected button

  • update_data takes a species name and returns a dict of data for just that species

So all together:

     source.data = update_data(species[new])

gets a new dict of data for the species corresponding to the pushed button, and sets source.data to it (which causes the plot to update)

Thanks,

Bryan

On Jan 10, 2017, at 8:02 PM, [email protected] wrote:

Hi Bryan

Can you explain what this piece of code is doing here:

source.data = update_data(species[new])

Thanks,

Pratik

On Tuesday, 10 January 2017 16:27:14 UTC-5, [email protected] wrote:

Hi Bryan,

Thank you for this example. I think this will help and I will definitely try to see the time series examples.

Thank you for your so quick responses. Really appreciate the support, especially what you are providing.

Thanks,

Pratik

On Tuesday, 10 January 2017 15:47:39 UTC-5, Bryan Van de ven wrote:

Hi,

Sometimes it’s good to take a step back and break up a problem into smaller pieces. First, a few comments:

  • You can put any print statements you like in the app, in the callbacks, etc. They will show in the console where you run the server

  • I’d suggest looking in the docs gallery for other time series examples, and getting the plot to work all by itself, without the server, first

Lastly, here is a complete but much simpler example that uses a radio button to update a plot, that you can run and study, in case it is instructive:

from [bokeh.io](http://bokeh.io) import curdoc, output_file
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, RadioButtonGroup
from bokeh.plotting import figure
from bokeh.sampledata.iris import flowers

species = ['setosa', 'versicolor', 'virginica']

def update_data(species):
    subset = flowers[flowers.species==species]
    return dict(
        sepal_width=subset.sepal_width,
        sepal_length=subset.sepal_length,
    )

source = ColumnDataSource()
source.data = update_data('setosa')

def callback(new):
    source.data = update_data(species[new])

button_group = RadioButtonGroup(labels=species, active=0)
button_group.on_click(callback)

plot = figure()
plot.circle(x='sepal_width', y='sepal_length', source=source)

curdoc().add_root(column(button_group, plot))

Thanks,

Bryan

On Jan 10, 2017, at 2:44 PM, [email protected] wrote:

Well, I appreciate your reply Bryan - but I am able to generate plots with the datatype I have. Do you think the other logic I have used is fine, meaning the RadioButtonGroup and the callback function?

Also, how and where can I see the printed objects? I am assuming in the command window, correct? If yes I am not able to apparently! Do you example snippet for that?

I did try this from one of your suggestions, but this did not work on server

Thanks
Pratik

On Tuesday, 10 January 2017 15:35:44 UTC-5, Bryan Van de ven wrote:
After making several changes, I ran the version below to get some information.

The problem I would say is with your data. You are converting everything to strings? I really doubt that’s what you want or intend, and if that’s the case, times need to be real datetime objects of some sort, not strings. If not, and you do want string values, you need to configure the plot ranges to be categorical:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#categorical-axes)

Thanks,

Bryan

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
import pandas as pd
from numpy.random import random, normal, lognormal

data = pd.DataFrame(data={'DepartmentProviderName':['Pysch1','Pysch1','Pysch2','Pysch2','Pysch3','Pysch3'],'CountAtStart':[10,15,16,14,11,10], 'Census':[10,12,15,12,13,14], 'Month':[9,9,9,9,10,10], 'Dt':['9/27/2016  1:00:00 AM','9/26/2016  1:00:00 AM','9/27/2016  1:00:00 AM','9/28/2016  1:00:00 AM','9/29/2016  1:00:00 AM','9/30/2016  1:00:00 AM']})
print(data)

menu = Select(options=['Med1','Med2'], value='Med1', title='Select DepartmentType')

test = ColumnDataSource(data=dict(Dt=[], Census=[],CountAtStart=[]))

def radio_button_group_handler(new):
    new = ['Pysch1', 'Pysch2','Pysch3'][new]
    print(new)
    current = data[(data.DepartmentProviderName == "%s" % new) & (data.Month == 9)]
    test.data = {
        'Dt'           : list(current.Dt),
        'Census'       : list(current.Census.apply(lambda v: "{:.2f}".format(v))),
        'CountAtStart' : list(current.CountAtStart.apply(lambda v: "{:.2f}".format(v))),
    }
    print(test.data)

depkey = ['Pysch1', 'Pysch2','Pysch3']
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = 'datetime')
facdept_plot.line(x='Dt', y='Census', source=test, line_dash=[4, 4], color='purple', alpha = 0.8, line_width=2, legend='Predicted')
facdept_plot.line(x='Dt', y='CountAtStart', source=test, color='blue', alpha = 0.3, line_width=2, legend='Actual')

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title='Test')

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

On Jan 10, 2017, at 2:20 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

test = pd.DataFrame(data={‘DepartmentProviderName’:[‘Pysch1’,‘Pysch1’,‘Pysch2’,‘Pysch2’,‘Pysch3’,‘Pysch3’],‘CountAtStart’:[10,15,16,14,11,10], ‘Census’:[10,12,15,12,13,14], ‘Month’:[9,9,9,9,10,10], ‘Dt’:[‘9/27/2016 1:00:00 AM’,‘9/26/2016 1:00:00 AM’,‘9/27/2016 1:00:00 AM’,‘9/28/2016 1:00:00 AM’,‘9/29/2016 1:00:00 AM’,‘9/30/2016 1:00:00 AM’]})

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=Census=,CountAtStart=))

def radio_button_group_handler(new):
current = data[(data.DepartmentProviderName == “%s” % new) & (data.Month == 9)]
test.data = {
‘Dt’ : current.Dt,
‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),
‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)
facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)
facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)

Hi Bryan,

How about now?

On Tuesday, 10 January 2017 15:03:24 UTC-5, Bryan Van de ven wrote:
Hi,

Almost, but not quite. I can’t run it because it uses some data that is not present. Can you supply the data? Or usually better, provide a minimal complete, runnable example with some kind of faked data.

Thanks,

Bryan

On Jan 10, 2017, at 1:53 PM, [email protected] wrote:

from bokeh.io import curdoc, output_file, show, push_notebook
from bokeh.layouts import column,row,widgetbox
from bokeh.models import HoverTool, Select, ColumnDataSource, BoxSelectTool, BoxZoomTool, CrosshairTool, ResetTool, ResizeTool, CustomJS, HBox, VBox, VBoxForm, LassoSelectTool
from bokeh.plotting import figure, reset_output
from bokeh.models.widgets import Panel, Tabs, DataTable, DateFormatter, TableColumn, Button, DatePicker, Button, RadioButtonGroup
from numpy.random import random, normal, lognormal

menu = Select(options=[‘Med1’,‘Med2’], value=‘Med1’, title=‘Select DepartmentType’)

test = ColumnDataSource(data=dict(Dt=,Census=,CountAtStart=))

def radio_button_group_handler(new):
current = data[(data.DepartmentProviderName == “%s” % new) & (data.Month == 9)]
test.data = {
‘Dt’ : current.Dt,
‘Census’ : current.Census.apply(lambda v: “{:.2f}”.format(v)),
‘CountAtStart’ : current.CountAtStart.apply(lambda v: “{:.2f}”.format(v)),
}

depkey = list(totData.DepartmentProviderName[totData.FacilityName == “St. Anne’s”].unique())
button_group = RadioButtonGroup(labels=depkey, active=0)
button_group.on_click(radio_button_group_handler)
SAHbutton = widgetbox(button_group, width = 500)

facdept_plot = figure(plot_width=1100, plot_height=600, x_axis_type = ‘datetime’)
facdept_plot.line(x=‘Dt’, y=‘Census’, source=test, line_dash=[4, 4], color=‘purple’, alpha = 0.8, line_width=2, legend=‘Predicted’)
facdept_plot.line(x=‘Dt’, y=‘CountAtStart’, source=test, color=‘blue’, alpha = 0.3, line_width=2, legend=‘Actual’)

l1 = column(SAHbutton, facdept_plot)
SAHtab = Panel(child = l1, title=‘Test’)

layout = Tabs(tabs = [SAHtab], width = 500)

final_layout = row(menu,layout)

curdoc().add_root(final_layout)


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/3d718896-634b-44e9-99d8-477cb0672e48%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/c0c9de54-32b4-49a9-8b2f-464845f27970%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/d20037f7-bcb5-45b9-bd2e-fe9d3ec5eeef%40continuum.io.

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