Skip to content

Instantly share code, notes, and snippets.

@rothnic
Last active June 4, 2016 11:49
Show Gist options
  • Save rothnic/1264a204776d711afeb4 to your computer and use it in GitHub Desktop.
Save rothnic/1264a204776d711afeb4 to your computer and use it in GitHub Desktop.
Example interactive app with bokeh charts and new server refactor
from bokeh.models.widgets import HBox, VBoxForm, Select
from bokeh.charts import Bar
from bokeh.io import curdoc
data = {'a': [1, 2, 3, 4],
'b': [3, 5, 4, 5],
'c': ['foo', 'bar', 'foo', 'bar']}
col_names = list(data.keys())
# because dimensions and attributes of chart are modeled, this could be auto generated
value_select = Select(
title='values', name='value_select',
options=col_names, value='a'
)
label_select = Select(
title='label', name='label_select',
options=col_names, value='c'
)
plot = Bar(data, values='a', label='b')
selectors = [value_select, label_select]
inputs = VBoxForm(children=selectors)
hbox = HBox(children=[inputs, plot])
chart_renderers = [renderer for renderer in plot.renderers if
hasattr(renderer, 'glyph')]
chart_renderers = {'rect': chart_renderers[0]}
def update_data():
updated_plot = Bar(data,
values=value_select.value,
label=label_select.value,
renderers=chart_renderers,
chart=plot)
def input_change(attrname, old, new):
update_data()
for selector in selectors:
selector.on_change('value', input_change)
curdoc().add_root(hbox)
@Punchwes
Copy link

Punchwes commented Jun 4, 2016

I've got a question when using rect to create interactive bar, My x_axis data is CSV file(locations), and it seems that rect's x data should only be list or array, how could i transform them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment