Skip to content

Instantly share code, notes, and snippets.

@schaunwheeler
Created April 26, 2015 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schaunwheeler/db994b9828d851d92c81 to your computer and use it in GitHub Desktop.
Save schaunwheeler/db994b9828d851d92c81 to your computer and use it in GitHub Desktop.
Illustration of Bokeh server failure to reflect all changes to document
from bokeh.browserlib import view
from bokeh.document import Document
from bokeh.session import Session
from bokeh.models.widgets.inputs import Select, AutocompleteInput
from bokeh.models.widgets.groups import CheckboxButtonGroup
from bokeh.models.widgets.buttons import Button
from bokeh.models.widgets.markups import Paragraph
from bokeh.models.widgets.layouts import VBox, HBox, VBoxForm
class MenuChange(object):
def __init__(self):
self.document = Document()
self.session = Session(load_from_config=False)
self.session.use_doc('menu_change')
self.session.load_document(self.document)
self.document.clear()
dates = [
u'2015-04-25', u'2015-04-01', u'2015-03-01', u'2015-02-01', u'2015-01-01', u'2014-12-01', u'2014-11-01',
u'2014-10-01', u'2014-09-01', u'2014-08-01', u'2014-06-01', u'2014-05-01', u'2014-04-01', u'2014-03-01',
u'2014-02-01', u'2014-01-01', u'2013-12-01', u'2013-11-01', u'2013-10-01', u'2013-09-01'
]
self.from_date_select = Select(value='2013-09-01', options=dates, name='from_date', title='From date')
self.to_date_select = Select(value='2015-04-25', options=dates, name='to_date', title='To date')
self.subject_select = Select(
value='Literacy', options=['Literacy', 'Mathematics', 'Science', 'History'], name='subject',
title='Subject')
self.metric_select = Select(
value='Achievement', options=['Achievement', 'Growth'], name='metric', title='Metric')
self.plot_type_select = Select(value='Bars', options=['Bars', 'Circles'], name='plot_type', title='Plot type')
self.teacher_autocomplete = AutocompleteInput(
completions=[
u'Fining, Brittany', u'Huselton, Laura', u'Bystrak, Chelsea', u'Turner, Raisa', u'Johnson, Erika',
u'Krebs, Jessica', u'Kuritsky, Sallie', u'Todd, Jennifer', u'Madrigal, Alyssa', u'Rascona, Lea',
u'Hughes, Jem', u'Francois, Ashley', u'Haves, Katherine', u'MacInnes, Rianne', u'MacCombie, Michael',
u'Savits, Juliet', u'Chudzik, Andrea', u'Rezin, Martha (Emily)', u'Fisher, Caroline', u'Choate, Molly'
], name='teacher', title='Teacher lookup')
self.scholar_autocomplete = AutocompleteInput(
completions=[
u'Abad Cruz, Jonathan', u'Abassa, Yacine', u'Abbey, Joshua', u'Abdellah, Sanai', u'Abderhamane, Malika',
u'Abdou, Abdoulaye', u"Abdul'Aziz, Khalisah", u'Abdulaziz, Asmaa', u'Abdulganiyu, Maryam',
u'Abelard, Quentin', u'Hoque, Shabkatul', u'Abrahams, Ariese', u'Abrahams, Makai', u'Abreu, Brianny',
u'Abreu, Isaiah', u'Abreu, Malakai', u'Abreu, Steven', u'Acevedo, Amanda', u'Acevedo, Amberlize',
u'Acevedo, Angelina'
], name='scholar', title='Scholar lookup')
self.skip_checkboxbuttongroup = CheckboxButtonGroup(active=[], labels=['1', '2', '3'], name='skip')
self.holdover_checkboxbuttongroup = CheckboxButtonGroup(active=[], labels=['1', '2', '3'], name='holdover')
self.state_exam_checkboxbuttongroup = CheckboxButtonGroup(
active=[], labels=['1', '2', '3', '4'], name='state_exam')
self.ell_status_checkboxbuttongroup = CheckboxButtonGroup(
active=[], labels=[u'Not an ELL', u'ELL - graduated', u'ELL - not graduated'], name='ell_status')
self.sped_checkboxbuttongroup = CheckboxButtonGroup(
active=[], labels=[
u'ICT', u'Other', u'SETSS', u'12-1-1', u'Counseling', u'Occupational Therapy',
u'Speech Language Therapy'
], name='sped')
self.school_checkboxbuttongroup = CheckboxButtonGroup(
active=[], labels=[
u'BB', u'BH', u'BS1', u'BS2', u'BX1', u'BX1MS', u'BX2', u'BX2MS', u'BX3', u'BX4', u'CH', u'CR', u'FG',
u'H1', u'H2L', u'H2U', u'H3', u'H4', u'H5', u'HC', u'HE', u'HK', u'HNC', u'HNW', u'HSLA', u'HW', u'PH',
u'RO', u'SG', u'US', u'UW', u'WB', u'WH'
], name='school')
self.school_type_checkboxbuttongroup = CheckboxButtonGroup(
active=[], labels=[u'ES', u'HS', u'MS'], name='school_type')
self.grade_checkboxbuttongroup = CheckboxButtonGroup(
active=[],
labels=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
name='grade')
self.menu_submit = Button(label='Submit', type='warning')
self.menu_submit.on_click(self.submit_menu)
self.menu_toggle = Button(label='Select plot criteria', type='primary')
self.menu_toggle.on_click(self.toggle_menu)
self.menu_reset = Button(label='Reset')
self.menu_reset.on_click(self.reset_menu)
self.controls = VBox(children=[VBoxForm(children=[self.menu_toggle])], height=35)
self.layout = VBox(children=[self.controls])
self.document.add(self.layout)
self.session.store_document(self.document)
self.session.store_objects()
def toggle_menu(self):
if len(self.controls.children[0].children) == 1:
self.controls.height = 300
self.menu_toggle.label = 'Close'
self.menu_toggle.type = 'default'
self.controls.children[0].children = [
HBox(children=[self.menu_submit, self.menu_toggle, self.menu_reset]),
HBox(children=[self.subject_select, self.metric_select, self.plot_type_select]),
HBox(children=[self.from_date_select, Paragraph(text=' '), self.to_date_select]),
HBox(children=[self.teacher_autocomplete, self.scholar_autocomplete]),
Paragraph(text=''),
Paragraph(text='School type'),
self.school_type_checkboxbuttongroup,
Paragraph(text=''),
Paragraph(text='School'),
self.school_checkboxbuttongroup,
Paragraph(text=''),
Paragraph(text='Grade'),
self.grade_checkboxbuttongroup,
Paragraph(text=''),
Paragraph(text='Skips'),
self.skip_checkboxbuttongroup,
Paragraph(text=''),
Paragraph(text='Holdovers'),
self.holdover_checkboxbuttongroup,
Paragraph(text=''),
Paragraph(text='State exams'),
self.state_exam_checkboxbuttongroup,
Paragraph(text=''),
Paragraph(text='ELL status'),
self.ell_status_checkboxbuttongroup,
Paragraph(text=''),
Paragraph(text='SpED services'),
self.sped_checkboxbuttongroup
]
else:
self.controls.height = 35
self.menu_toggle.label = 'Select plot criteria'
self.menu_toggle.type = 'primary'
self.controls.children[0].children = [self.menu_toggle]
self.session.store_objects(self.controls)
def submit_menu(self):
self.toggle_menu()
def reset_menu(self):
self.__init__()
def run(self, do_view=False, poll_interval=0.5):
link = self.session.object_link(self.document.context)
if do_view:
print("Please visit %s to see the plots" % link)
view(link)
if poll_interval is not None:
print("\npress ctrl-C to exit")
self.session.poll_document(self.document, interval=poll_interval)
mc = MenuChange()
mc.run(True, poll_interval=0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment