Can I switch between output_notebook and output_file in an IPython laptop session using Bokeh?

I am wondering if it is possible to generate static HTML outputs and embedded graphics using Bokeh in the same IPython laptop. What I am seeing now is that as soon as I either call output_notebook() or output_file("myfile.html") , I am stuck using this output modality. For example, if I initially use output_notebook , then calling output_file does not create an output file.

+6
source share
2 answers

reset_output() before the next call to output_notebook or output_file 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) 

The first and third shows in a laptop, the second in a browser.

+2
source

You can create static HTML using the following code (adapted from the 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 is not a problem when combined with output_notebook()

0
source

Source: https://habr.com/ru/post/975538/


All Articles