After some more experimentation, I believe this may be a bug. Below is a minimal example case (running bokeh serve example.py. A figure is shown with an initial plot. Then different things can happen.
Case 1:
The user does not update the view, but only clicks the button. We don’t have the server change the range values. In this case, the view automatically updates to fit the updated data.
Case 2:
The user does update the view before clicking the button. We don’t have the server change the range values. In this case, the view does not automatically update to fit the updated data and shows the manually selected view. The reset button on the client side will fit the view to the new data.
Case 3:
The user does not update the view, but only clicks the button. We have the server update the range ends to specific non-None values. In this case, the view automatically updates to fit the updated data. The range values we set are ignored.
Case 4:
The user updates the view and clicks the button. We have the server update the range ends to specific non-None values. In this case, the view is set to what we set the range values to be on the server side. The reset button auto fits the new data.
Case 5:
The user does not update the view, but only clicks the button. We have the server update the range ends to None. In this case, the view automatically updates to fit the updated data.
Case 6:
The user updates the view and clicks the button. We have the server update the range ends to None. In this case, the view shows nothing. The reset button auto fits the new data.
The two cases that seem to work contrary to what I would expect are cases 3 and 6. For case 3, I would expect that the range setting would override the auto data fitting. For case 6, I would expect setting the range ends to None to override the manual fit chosen, and re-enable auto fitting. Notably, these range changes are used by the client side in cases 4 and 5, so it doesn’t have to do with the client not getting the updates from the server. It seems more to be a problem with the server not being able to change whether or not the auto fitting is enabled on the client. Is there some way to do this that I’m missing? Is this a bug? Or is this the expected behavior? Thank you for your time!
example.py
import numpy as np
import pandas as pd
from bokeh.models import Button
from bokeh.plotting import Figure, curdoc
from bokeh.layouts import column
from bokeh.models.sources import ColumnDataSource
def dashboard():
data0 = pd.DataFrame({'y': [1, 2, 3] * 5, 'x': np.arange(15)})
data1 = pd.DataFrame({'y': [4, 5, 6] * 5, 'x': np.arange(15) + 1})
data_source = ColumnDataSource(data0)
button = Button()
figure = Figure()
figure.line('x', 'y', source=data_source)
def updata_data():
new_data = ColumnDataSource.from_df(data1)
data_source.data.update(**new_data)
# figure.x_range.start = None
# figure.x_range.end = None
# figure.y_range.start = None
# figure.y_range.end = None
button.on_click(updata_data)
curdoc().add_root(column(button, figure))
dashboard()