I'm wondering if it is possible to generate static HTML output and inline plots using Bokeh in the same IPython notebook. What I am currently seeing is that once I either call output_notebook()
or output_file("myfile.html")
I am stuck using that output modality. For example, if I initially use output_notebook
, subsequently calling output_file
does not create an output file.
Asked
Active
Viewed 3,586 times
12

Chris Fonnesbeck
- 4,143
- 4
- 29
- 30
-
One correction: It seems that I can initially use `output_file` followed by `output_notebook`, but not the other way around. – Chris Fonnesbeck Sep 19 '14 at 14:18
2 Answers
13
reset_output()
before the next output_notebook
or output_file
call works at least in version 0.10.0 .
# cell 1
from bokeh.plotting import figure, show, output_notebook, output_file, reset_output
p = figure(width=300, height=300)
p.line(range(5), range(5))
output_notebook()
show(p)
# cell 2
reset_output()
output_file('foo.html')
show(p)
# cell 3
reset_output()
output_notebook()
show(p)
First and third show in notebook, second shows in browser.

paavo
- 145
- 1
- 5
0
You can create a static HTML using the following code (adapted from example here):
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import file_html
plot = figure()
plot.circle([1,2], [3,4])
html = file_html(plot, CDN, "my plot")
with open('test.html', 'w') as f:
f.write(html)
This works no trouble in conjunction with output_notebook()

SimonBiggs
- 816
- 1
- 8
- 18
-
I have a similar situation, but my plots are created in a loop. Is it possible to append each plot to create a single html file with all of them on it? – mad5245 Dec 17 '15 at 17:22
-
Sorry for the overlook. I was thinking way to hard about that one. For reference you simply change the 'w' to 'a' just like with any file. – mad5245 Dec 17 '15 at 17:29