Range Slider and automatic OLS fit

Hello everyone,

I would like to do a linear fit on a portion of a scatter plot dynamically when a Xaxis range slider is moved (or alternativelly with the Lasso tool if you think it is easier to implement). Do you know if this doable in a simple way or where I could find examples of such application?