Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bokeh.io import show
- from bokeh.layouts import column
- from bokeh.models import DataTable, TableColumn, Button, CustomJS, ColumnDataSource
- from bokeh.plotting import figure
- from bokeh.io import output_notebook
- output_notebook()
- fig = figure(x_range=["a", "b"],
- plot_height=350,
- plot_width=490,
- tools="box_edit",
- toolbar_location="right")
- source_plot = ColumnDataSource(data={"Column": ["a", "b"], "Aggresult": [0,0]})
- bar = fig.vbar(x='Column', top='Aggresult', width=0.9, source=source_plot,
- fill_color='#97F0AA', line_color="black", name="main_vbar")
- sum_button = Button(label="1st", width=100)
- mean_button = Button(label="2nd", width=100)
- download_json = Button(label="Download json", width=70)
- sum_button.js_on_click(CustomJS(args=dict(source_plot=source_plot),
- code="""
- source_plot.data["Aggresult"] = [100, 150];
- source_plot.change.emit();
- """))
- mean_button.js_on_click(CustomJS(args=dict(source_plot=source_plot),
- code="""
- source_plot.data["Aggresult"] = [50, 30];
- source_plot.change.emit();
- """))
- download_json.js_on_click(CustomJS(code="""
- function saveText(text, filename){
- var a = document.createElement('a');
- a.setAttribute('href', 'data:text/plain;charset=utf-8,'+encodeURIComponent(text));
- a.setAttribute('download', filename);
- a.click()
- }
- var obj = Bokeh.documents[0].to_json_string();
- saveText( JSON.stringify(obj), "filename.json" );
- """))
- show(column(row(sum_button, mean_button, download_json), fig))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement