# Login btnLogin = wd.Button(label="Login") btnReset = wd.Button(label="Reset") name = wd.TextInput(title="Name", placeholder="enter name ....") pwd = wd.TextInput(title="Password", placeholder="enter password ....") # Study majors = wd.RadioButtonGroup(labels=["CS", "Stat", "Math", "EIE", "Energy", "HSS", "SME"]) text = wd.Paragraph(text="Press button to start .... ") answer = wd.Paragraph(text="") btnRandom = wd.Button(label="Choose For Me") login = layout( [ [ wb(name) ], [ wb(pwd) ], [ wb(btnLogin), wb(btnReset) ] # side by side ] ) major = layout( [ [ wb(majors, width=800) ], [ wb(text, btnRandom, answer) ] ] ) page1 = wd.Panel(child=login, title="Login") page2 = wd.Panel(child=major, title="Major") tabs = wd.Tabs( tabs=[page1, page2] ) def choose():
refresh.on_click(refreshByFilter) # course info table columns = [ wd.TableColumn(field='id', title='Course ID'), wd.TableColumn(field='title', title='Title'), wd.TableColumn(field='dept', title='Department'), wd.TableColumn(field='credits', title='Credit'), wd.TableColumn(field='instructor', title='Instructor'), ] table = wd.DataTable(source=ColumnDataSource(), columns=columns, width=800) # course info layout courseInfo = layout([ [wb(btnGroupLetters, width=1000)], [wb(btnGroupTitle), wb(btnGroupDept)], [ wb(title_input), wb(paragraph, optionGroup, width=100), wb(dept_input), ], [wb(refresh, width=100)], [wb(table)], ]) # statistics page widges for stu in fetchRows( "select gpa, year from lgu.student where dept_name = 'accounting'"): yr, g = stu['year'], dct[stu['gpa']] STAdata[yr][g] += 1
dept_select.on_change("value", select_change) # Deal with missing grades # Some of students' grades are missing so we need to fill it with 0 def check(grade, count): standard = ['A+', 'A', 'B+', 'B', 'C+', 'C', 'D+', 'D', 'F'] for i in range(9): if standard[i] not in grade: count.insert(i, 0) return count # Pages Layout layout_tab1 = layout([[wb(GroupLetters, width=1000)], [wb(Group_choices, width=400), wb(Department_choices)], [ wb(title_input), wb(Text_Instruction, options, width=100), wb(dept_input) ], [wb(button_refresh, width=100)], [wb(data_table)]]) layout_tab2 = layout([[wb(dept_select), chart]]) # Tabs layout tab1 = wd.Panel(child=layout_tab1, title="Course Info") tab2 = wd.Panel(child=layout_tab2, title="Statistics") tabs = wd.Tabs(tabs=[tab1, tab2]) # Display
rows = select2() for row in rows: print(row['dept_name'], row['title']) def select3(title): tsql = "SELECT * FROM lgu.course where title like %s" print(tsql, title) with sqlConn.cursor(as_dict=Ture) as cursor: cursor.execute(tsql, title) rows = cursor.fetchall() for row in rows: print(row['dept_name'], row['title']) select3(title="bio%") button = wd.Button(label="Refresh") textbox = wd.TextInput(title="Name", value="", placeholder="enter name ....") def buttonClick(): print('button click') def textChange(attr, old, new): print(new) button.on_click(buttonClick) textbox.on_change("value", textChange) curdoc().add_root( wb(button, textbox) )
toolbar_location=None, tools="") p.vbar_stack(years, x='gpa', width=0.9, color=colors, source=source, legend=[value(x) for x in years]) p.y_range.start = 0 p.legend.location = "top_center" p.legend.orientation = "vertical" layout_query = layout([ [wb(btnGroupLetters, width=1000)], [wb(btnGroupTitle), wb(btnGroupDept)], [wb(title_input), wb(paragraph, optionGroup, width=100), wb(dept_input)], [wb(refresh, width=100)], [wb(table)], ]) layout_chart = layout([[wb(deptSelect)]]) tab1 = wd.Panel(child=layout_query, title="Course Info") tab2 = wd.Panel(child=layout_chart, title="Statistics") tabs = wd.Tabs(tabs=[tab1, tab2]) curdoc().add_root(tabs)
placeholder='contains....') dept_input = wd.TextInput(title='Department:', value='', placeholder='contains....') refresh = wd.Button(label='Refresh') btnGroupTitle = wd.RadioButtonGroup( name='title', labels=['begins with...', '...contains...', '...ends with'], active=1) btnGroupDept = wd.RadioButtonGroup( name='dept', labels=['begins with...', '...contains...', '...ends with'], active=1) page_info = layout( [[wb(btnGroupLetters, width=1000)], [wb(btnGroupTitle), wb(btnGroupDept)], [wb(title_input), wb(paragraph, optionGroup, width=100), wb(dept_input)], [wb(refresh, width=100)], [wb(table)]]) # +----------+ Statistics +----------+ selectDept = wd.Select(title='Department:', value='', options=dept_list()) colors = ['#c9d9d3', '#718dbf', '#e84d60'] gpa = ['A+', 'A', 'B+', 'B', 'C+', 'C', 'D+', 'D', 'F'] years = ['2015', '2016', '2017'] data = {} data['gpa'] = gpa
from bokeh.io import show, curdoc from bokeh.plotting import figure from bokeh.layouts import widgetbox as wb, layout from bokeh.models import widgets as wd, ColumnarDataSource from bokeh.core.properties import value # Login btnLogin = wd.Button(label="Login") btnReset = wd.Button(label="Reset") name = wd.TextInput(title="Name", placeholder="enter name ....") pwd = wd.TextInput(title="Password", placeholder="enter password ....") login = layout([[wb(name)], [wb(pwd)], [wb(btnLogin), wb(btnReset)]]) # Study majors = wd.RadioButtonGroup( labels=["CSC", "STA", "MAT", "EIE", "ENE", "HSS", "SME"]) text = wd.Paragraph(text="Press button to start ....") answer = wd.Paragraph(text="") btnRandom = wd.Button(label="Choose for me") study = layout([[wb(majors, width=800)], [wb(text, btnRandom, answer)]]) page1 = wd.Panel(child=login, title="login") page2 = wd.Panel(child=study, title="Study") tabs = wd.Tabs(tabs=[page1, page2]) curdoc().add_root(tabs)