This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotebook_embed_tohtml.py
87 lines (61 loc) · 2.23 KB
/
notebook_embed_tohtml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import yaml
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
from bokeh.themes import Theme
from bokeh.sampledata.sea_surface_temperature import sea_surface_temperature
def modify_doc(doc):
df = sea_surface_temperature.copy()
source = ColumnDataSource(data=df)
plot = figure(x_axis_type='datetime', y_range=(0, 25),
y_axis_label='Temperature (Celsius)',
title="Sea Surface Temperature at 43.18, -70.43")
plot.line('time', 'temperature', source=source)
def callback(attr, old, new):
if new == 0:
data = df
else:
data = df.rolling('{0}D'.format(new)).mean()
source.data = ColumnDataSource(data=data).data
slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days")
slider.on_change('value', callback)
doc.add_root(column(slider, plot))
doc.theme = Theme(json=yaml.load("""
attrs:
Figure:
background_fill_color: "#DDDDDD"
outline_line_color: white
toolbar_location: above
height: 500
width: 800
Grid:
grid_line_dash: [6, 4]
grid_line_color: white
"""))
from bokeh.resources import CDN
from bokeh.embed import file_html
t=modify_doc
html = file_html(modify_doc, CDN, "bokey_seasurface")
Html_file= open("templates/bokey_seasurface.html","w")
Html_file.write(html)
Html_file.close()
#show(modify_doc) # notebook_url="http://localhost:8888"
from bokeh.io import show, output_file
from bokeh.plotting import figure
from bokeh.models import Button, CustomJS
from bokeh.layouts import column
f1 = figure()
f1.x(x=[1, 2, 3], y=[3, 2, 1])
main_row = column(f1)
b = Button(label='Add plot',
callback=CustomJS(args=dict(main_row=main_row),
code="""
f = Bokeh.Plotting.figure();
f.cross({x: [1, 2, 3], y: [3, 2, 1]});
main_row.children.push(f);
main_row.properties.children.change.emit();
"""))
main_row.children.append(b)
output_file('templates/bokeh_add_plot_no_server.html')
#curstate().file['resources'].js_components.append('bokeh-api')
show(main_row)