Closed mfesan36 closed 1 year ago
I cannot find a way to force pyshiny capture interactions that happen on the plot. To be more clear, when I select a portion of plot by interval selector (see code below) the observe method gets ignored.
At least currently, the .observe()
method on widget objects don't work the way you might expect them to in shinywidgets (i.e., .observe()
callback won't re-execute when widget attributes change).
However, by combining Shiny's @reactive.Effect()
with shinywidgets reactive_read()
you can effectively "observe" (i.e., re-execute a callback function) whenever particular traits (and/or reactive values) change.
Seems as though this is the sort of server-side logic you're looking for?
def server(input: Inputs, output: Outputs, session: Session):
time_series_fig = plt.figure()
line = plt.plot([y1, y2])
time_series_fig.interaction = FastIntervalSelector(marks=[line], scale=line.scales["x"])
register_widget("bqplot_line", time_series_fig)
scat_fig = plt.figure(
title="Scatter of time series slice selected by the interval selector"
)
register_widget("bqplot_scat", scat_fig)
scat = plt.scatter([], [], colors=["red"], stroke="black")
@reactive.Effect()
def _():
selected = reactive_read(time_series_fig.interaction, "selected")
if selected is None:
return
idx = np.arange(int(selected[0]), int(selected[1]))
with scat.hold_sync():
scat.x = line.y[0][idx]
scat.y = line.y[1][idx]
I cannot find a way to force pyshiny capture interactions that happen on the plot. To be more clear, when I select a portion of plot by interval selector (see code below) the observe method gets ignored. If you click on top chart an interval selector will appear, you can adjust the width by moving your mouse and fix the interval by a double click: