Advertisement
Higem

Untitled

Apr 2nd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. from bokeh.io import show
  2. from bokeh.layouts import column
  3. from bokeh.models import DataTable, TableColumn, Button, CustomJS, ColumnDataSource
  4. from bokeh.plotting import figure
  5. from bokeh.io import output_notebook
  6.  
  7. output_notebook()
  8.  
  9.  
  10. fig = figure(x_range=["a", "b"],
  11. plot_height=350,
  12. plot_width=490,
  13. tools="box_edit",
  14. toolbar_location="right")
  15.  
  16. source_plot = ColumnDataSource(data={"Column": ["a", "b"], "Aggresult": [0,0]})
  17. bar = fig.vbar(x='Column', top='Aggresult', width=0.9, source=source_plot,
  18. fill_color='#97F0AA', line_color="black", name="main_vbar")
  19.  
  20. sum_button = Button(label="1st", width=100)
  21. mean_button = Button(label="2nd", width=100)
  22. download_json = Button(label="Download json", width=70)
  23.  
  24.  
  25.  
  26. sum_button.js_on_click(CustomJS(args=dict(source_plot=source_plot),
  27. code="""
  28. source_plot.data["Aggresult"] = [100, 150];
  29. source_plot.change.emit();
  30. """))
  31.  
  32. mean_button.js_on_click(CustomJS(args=dict(source_plot=source_plot),
  33. code="""
  34. source_plot.data["Aggresult"] = [50, 30];
  35. source_plot.change.emit();
  36. """))
  37.  
  38.  
  39. download_json.js_on_click(CustomJS(code="""
  40. function saveText(text, filename){
  41. var a = document.createElement('a');
  42. a.setAttribute('href', 'data:text/plain;charset=utf-8,'+encodeURIComponent(text));
  43. a.setAttribute('download', filename);
  44. a.click()
  45. }
  46.  
  47. var obj = Bokeh.documents[0].to_json_string();
  48. saveText( JSON.stringify(obj), "filename.json" );
  49. """))
  50.  
  51.  
  52. show(column(row(sum_button, mean_button, download_json), fig))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement