Trigger resize of plot after JS changes to toolbar or legend

To make my Bokeh figures responsive on mobile devices I issue a couple of changes on the JS side, such as removing the toolbar or changing the legend location. Below is an example in which button clicks simulate such changes.
I wonder whether it is possible to trigger some sort of resizing of the plot after such a change, such that the plot uses the new space previously occupied by the toolbar/legend. As far as I can see this type of resizing is not affected by sizing_mode or width_policy.

from bokeh.plotting import figure, show
from bokeh.models import Button, CustomJS, Legend, LegendItem
from bokeh.layouts import layout

button1 = Button(label='Remove toolbar')
button2 = Button(label='Shift legend left')

button1.js_on_event('button_click', CustomJS(code=
    "Bokeh.documents[0].get_model_by_name('fig').toolbar.visible = false"))
button2.js_on_event('button_click', CustomJS(code=
    "Bokeh.documents[0].get_model_by_name('legend').location = [-120, 10]"))

p = figure(title="Example figure", name='fig', toolbar_location='left')
c = p.line([0, 1], [0, 1])
legend = Legend(items=[LegendItem(label='Legend entry', renderers=[c])], 
                name='legend', location='bottom_right')
p.add_layout(legend, 'right')
show(layout([[button1, button2], p]))

As I side note, making the legend invisible triggers such a resize, so it seems to be possible in principle.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.