Last active
December 5, 2016 20:03
-
-
Save RafaelPais/b810dcfbfce72075ef00c9d4be26bd25 to your computer and use it in GitHub Desktop.
Layout issues
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Nov 28 09:33:55 2016 | |
@author: Rafael Pais | |
""" | |
from bokeh.layouts import row, column | |
from bokeh.models.widgets import Select, Div, RadioButtonGroup | |
from bokeh.io import curdoc | |
from bokeh.plotting import figure | |
from bokeh.layouts import gridplot | |
#div blank | |
div = Div(text="""<font size="3">""", width=1000, height=20) | |
TOOLS = "wheel_zoom, pan, save, box_zoom, reset" | |
radio = RadioButtonGroup(labels=["Option 1", "Option 2"], active=0) | |
ticker_1a_option = ['Chart 1', 'Chart 2'] | |
ticker_1b_option = [] | |
ticker_2a_option = ['Chart A', 'Chart B'] | |
ticker_2b_option = [] | |
ticker_1a = Select(title='Ticker 1a:', value = '', options=ticker_1a_option) | |
ticker_1b = Select(title='Ticker 1b:', value = '', options=ticker_1b_option) | |
ticker_2a = Select(title='Ticker 2a:', value = '', options=ticker_2a_option) | |
ticker_2b = Select(title='Ticker 2b:', value = '', options=ticker_2b_option) | |
#only figure | |
def figure_ticker(n): | |
plts=[] | |
ps = [figure(plot_width=550, plot_height=380, tools = TOOLS) for i in range (n)] | |
for i in range (n): | |
ps[i].circle() | |
ps[i].yaxis.axis_label_text_font_size = "12 pt" | |
ps[i].xaxis.major_label_orientation = "vertical" | |
ps[i].xaxis.major_label_standoff = 50 | |
ps[i].yaxis.major_label_text_color = "black" | |
ps[i].background_fill_color = "dimgray" | |
ps[i].background_fill_alpha = 1 | |
ps[i].outline_line_width = 1 | |
ps[i].outline_line_alpha = 0.5 | |
ps[i].outline_line_color = "black" | |
plts.append(ps[i]) | |
p = gridplot(plts, ncols=2, responsive=False) | |
return p | |
# radio option | |
def update_radio(new): | |
if new == 0: | |
control = row(ticker_1a, ticker_1b) | |
layout.children[1]= row(control) | |
else: | |
control = row(ticker_2a , ticker_2b ) | |
layout.children[1]= row(control) | |
# update ticker_1b | |
def update_ticker_1a(attrname, old, new): | |
list_options=[] | |
select = ticker_1a.value | |
ticker_1b_dict = {'Chart 1' : ['1', '2', '3'], 'Chart 2' : ['1', '2', '3', '4']} | |
options = ticker_1b_dict[select] | |
for i in options: | |
list_options.append(i) | |
ticker_1b.options = list_options | |
def update_ticker_1b(attrname, old, new): | |
n = ticker_1b.value | |
layout.children[2] = figure_ticker(int(n)) | |
# ticker_2b update | |
def update_ticker_2a(attrname, old, new): | |
list_options=[] | |
select = ticker_2a.value | |
ticker_2b_dict = {'Chart A' : ['5', '6', '7'], 'Chart B' : ['5', '6']} | |
options = ticker_2b_dict[select] | |
for i in options: | |
list_options.append(i) | |
ticker_2b.options = list_options | |
# ticker_1b update layout 3 | |
def update_ticker_2b(attrname, old, new): | |
n = ticker_2b.value | |
layout.children[2] = figure_ticker(int(n)) | |
ticker_1a.on_change('value', update_ticker_1a) | |
ticker_1b.on_change('value', update_ticker_1b) | |
ticker_2a.on_change('value', update_ticker_2a) | |
ticker_2b.on_change('value', update_ticker_2b) | |
radio.on_click(update_radio) | |
options = column([radio], width=200) | |
control = row([ticker_1a, ticker_1b]) | |
layout = column(options, control, div) | |
curdoc().add_root(layout) | |
curdoc().title = 'Layout' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment