Hello All,
I have a usecase of creating dynamic bokeh plots on the panel based on the option from Select widget. However, when updating the plot object the scroll position of Select widget is reseting to top. Here is a sample code to replicate the issue.
import panel as pn
import bokeh.plotting as bp
import numpy as np
pn.extension('bokeh')
# Create sample data and options
options = [f"Option {i}" for i in range(25)]
select = pn.widgets.Select(name='Select Plot', options=options, size=5)
# Initialize empty plot
def create_plot(option=""):
if not option:
return bp.figure(width=400, height=300, title="Select an option")
# Generate sample data based on selection
x = np.linspace(0, 10, 100)
y = np.sin(x + hash(option) % 10)
p = bp.figure(width=400, height=300, title=f"Plot for {option}")
p.line(x, y, line_width=2)
return p
plot_pane = pn.pane.Bokeh(create_plot())
@pn.depends(select.param.value, watch=True)
def update_plot(value):
plot_pane.object = create_plot(value)
# Layout
layout = pn.Row(select, plot_pane)
layout.servable()
layout.show(1122)
Expected Behavior: The Select widget should maintain its scroll position when plots are updated.
Current Behavior: Select widget scrolls back to top after each plot update.
Has anyone encountered this issue or know of a workaround? I need to maintain the dynamic plot creation approach due to the variable number of plots in my actual application.