Different sizing_mode for output_file

I’m looking for a feature to change sizing_mode when output_file is called.
I can of course change it manually directly in the html file when it isaved but don’t think it is a smart solution.

fig = figure(sizing_mode="stretch_width")
# This is what I use now 
# but want more smarter solution within bokeh library if there is one
with open(path_to_file, 'r') as f:
    stretch_width = f.read().replace('stretch_width', 'stretch_both')
with open(path_to_file, 'w') as f:


@somebody I’m not sure I understand the situation. You want to change it in a file and then overwrite that same filename? In that case why not save it with the mode you want in the first place?

hi Bryan
I have sizing_mode="stretch_width" on the web page.
If I change it write before calling output_file(filename=path_to_file) like this:

fig = figure(sizing_mode="stretch_width")
fig.sizing_mode = "stretch_both"

then the web page will display the change as well but I need only change it in the file but not on the webpage.

Sorry, I am still not understanding. What does “on the webpage” mean here, exactly? Do you mean you are also passing the figure to one of the bokeh.embed APIs first before saving? Then you should be able to change the sizing mode after the embedding, but before saving. Are you saying that does not work? Then we need a complete Minimal Reproducible Example to actually run and investigate directly. Otherwise, please describe all the steps you are taking more fully and in more detail.

Sorry for confusing you. I’ll try to explain what I mean.
I have a Flask app with dinamically creating Bokeh graphs based on user’s input. Those plots are displayed using "stretch_width" mode. When the plot is displayed on the webpage I want to save it as well as a html file output_file(filename=path_to_file) but with different sizing_mode. This is a simplified snippet from the code:

def some_route():
fig = figure(sizing_mode="stretch_width")
fig.line(0, 0)
output_file(filename=path) # here I need to save the plot with diffferent sizing_mode but not change it when template is rendered
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(fig)
return render_template('index.html', plot_script=script, plot_div=div, js_resources=js_resources, css_resources=css_resources)

@somebody In that case is there some reason you can’t set the sizing mode for save first, then save, then update the sizing mode before calling components ?

Right :slight_smile: