I’ve created a simple example where I plot a scatter plot with random points alongside a button that refreshes the plot with new data points. The layout uses GridSpec such that the Bokeh plot takes up 3/4 of the horizontal space, while the button gets the remaining 1/4. When I launch the script with panel serve
the Bokeh plot doesn’t use all of the space that’s available. Only after refreshing the data a couple of times does it use all of the available space:
Am I doing something wrong, or is this normal behaviour? I want the Bokeh pane to use all of the available space from the moment it’s rendered.
The code I used can be found below:
from numpy.random import default_rng
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
import panel as pn
rng = default_rng()
def calculate_coordinates():
x_coordinates = rng.standard_normal(10)
y_coordinates = rng.standard_normal(10)
return {"x": x_coordinates, "y": y_coordinates}
data = calculate_coordinates()
source = ColumnDataSource(data)
def refresh_data(event):
new_data = calculate_coordinates()
new_source = ColumnDataSource(new_data)
source.data.update(new_source.data)
plot = figure()
plot.sizing_mode = "stretch_both"
plot.circle(x="x", y="y", source=source)
button = pn.widgets.Button(name="Replot", button_type="primary", sizing_mode="stretch_both")
button.on_click(refresh_data)
grid = pn.GridSpec(sizing_mode="stretch_both")
grid[0, 0:3] = pn.pane.Bokeh(plot)
grid[0, 3] = button
grid.servable()