Interactive Data Selection in Plot?

Hi :wave:

I currently need to build an app where the user has to review data (timeseries plots) and mark anomalies.

Ideally, I’d want a lasso or box selection where I can report back to Python and perform an action based on this selection…

Is there some way to do this (maybe with some component)?

Would hate to switch to dash/ plotly for this single app…


Streamlit bokeh events from @ash2shukla might be exactly what you are looking for:

This looks great, thanks…

I try to reuse the plot selection example. However, I’d like to remember the indices and also color the selection in red whereas the normal circles are black.
I also added SessionState to keep state, but somehow this does not work (I store the selection in session_state.indices and add to them using:

session_state.indices = list(set(session_state.indices + indices)).

Plotting if off by one though. I only see the previous selection…

Would you know a trick/ example how I can select data multiple times? The marked points should just increase (so they need to be preserved between individual selections). I’d also need a reset option or better an undo previous addition…

I added a color column to my df that is modified depending on session_state.indices at the start (to preserve old selections)

What I see:

  1. all dots black
  2. 1st selection (in orange); once I release all dots black again
  3. 2nd selection (in orange); once I release the first selection appears
  4. …

If you press&hold “Shift” in Bokeh plot while selecting, you can add new datapoints to current selection. I hope this is what you are a asking for. For more detailed session state stuff I guess I’m not qualified enough :yum: