saving bokeh plots to static html without modifying global state

I have a function within which i want to save a plot to static html. It seems the way to save to static html is to call output_file() but this modifies global state which causes me a lot of other problems. I want to be able to write a function that can output to a file but not affect the global state. I tried plotting.save() but I get errors about the resources not being setup and when I explicitly pass the resources I get an error that seems to amount to the global variable _default_file not being set.

This is the latter error which I get when I try to do this:

plotting.save(file, obj=fig, resources=resources.Resources(mode=‘inline’, root_dir=None, minified=False))

Is there any way to save to static html without having to modify global state?

TypeError: 'NoneType' object is not subscriptable

I have a function within which i want to save a plot to static html. It seems the way to save to static html is to call output_file() but this modifies global state which causes me a lot of other problems. I want to be able to write a function that can output to a file but not affect the global state. I tried plotting.save() but I get errors about the resources not being setup and when I explicitly pass the resources I get an error that seems to amount to the global variable _default_file not being set.

This is the latter error which I get when I try to do this:

plotting.save(file, obj=fig, resources=resources.Resources(mode=‘inline’, root_dir=None, minified=False))

Is there any way to save to static html without having to modify global state?

TypeError: 'NoneType' object is not subscriptable

Tom, you have uncovered a bug in plotting.save, it should not (necessarily) rely on any global state, if all the inputs are provide. I will make an issue to fix this. In the mean time, you can use bokeh.embed.file_html directly:

    from bokeh.plotting import figure 
    from bokeh.embed import file_html 
    from bokeh.resources import INLINE 

    p = figure() 
    p.circle([1,2], [3,4]) 

    html = file_html(p, INLINE, 'title') 
     
    with io.open("foo.html", "w", encoding="utf-8") as f: 
                f.write(decode_utf8(html)) 

Note that if you need finer control over the document that gets generated, there are other functions in bokeh.embed that will give you just the raw components that you can template into your own documents how ever you need to. Thanks for the issue report.

Bryan

···

On Friday, December 26, 2014 5:45:52 PM UTC-6, Tom wrote: