Last active
June 4, 2016 11:49
-
-
Save rothnic/1264a204776d711afeb4 to your computer and use it in GitHub Desktop.
Example interactive app with bokeh charts and new server refactor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
oh,no T T
in the new version, is there any solution to achieve the same thing?