Hi,
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")
...
output_file(filename=path_to_file)
save(fig)
# 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:
f.write(stretch_width)
@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?
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:
@app.route("/")
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
save(fig)
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 ?