rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.36k stars 1.87k forks source link

Feature request: freehand/lasso selection for brushing #2072

Open federicomarini opened 6 years ago

federicomarini commented 6 years ago

During a conversation at eRum2018 with @bborgesr, I managed to show a use case (out of potentially many) for this feature, which we currently (with some js flavour) implemented in our package, iSEE (http://bioconductor.org/packages/release/bioc/html/iSEE.html). She suggested me to open up an issue officially for better visibility and tracking - my guess is indeed many people would fancy the freehand selection, especially when the "point cloud" is not exactly rectangular and/or the edges could play nicer if defined as a path.

A running demo for the package/app can be found here: http://shiny.imbei.uni-mainz.de:3838/iSEE_PBMC4k/ - in this case, some panels are pre-linked to each other, so you would just need to interact with the first one.

More in detail, we did implement a lasso-polygon-selection, which works by clicking point by point the edges of the polygon to be (closed once the start and end coincide). Nonetheless, it would be extremely cool to have such selection supported/streamlined in the official Shiny framework.

Thoughts from the dev team?

jcheng5 commented 6 years ago

This is quite impressive work! Congrats on a very cool app! It does very clearly demonstrate the value in the ability to select irregularly shaped regions, thanks for that.

The main downside I see to your approach to lassoing is that, being implemented on the server side, you have to wait for a replot for each point that's added--and for the same reason, it's difficult to imagine how you could edit the polygon by dragging, adding, or removing points, which would also be nice. It makes a lot of sense for Shiny to add this as a mostly JavaScript based feature, as is the case with the rectangular brushing we have today.

federicomarini commented 6 years ago

Hi @jcheng5, thanks a lot for the feedback.

Exactly as you said, this is a typical case where the shapes to be selected can and often do assume weird (or anyway, irregular) forms.

And as you say, the approach we have cannot address the points you just mentioned. We (mostly @LTLA and @kevinrue actually) still took it on to implement this first "clunky" version, because of the added value to have the alternative.

Can I interpret your last sentence as a "we can put it on the next todo list" with hope & dreams 😄 ?

LTLA commented 3 years ago

FWIW I got started on re-implementing this without re-rendering the entire plot (iSEE/ISEE#537), just by using insertUI() and removeUI() to slap on span elements for the lasso waypoints and the lines based on the coords_css in the click information.

It mostly works except that it does not deal with resizing of the window. Currently, I use a custom handler to detect resizing events and just give up, i.e., delete any unfinished lasso rather than attempting to remap the old coordinates to match the resized plot. (Closed lassos are handled via a different mechanism, so they stick around and are handled properly on resize.)

If shiny could expose a mechanism for mapping data coordinates to CSS coordinates, that would allow me to handle resize events properly. I presume this already exists somewhere in the JS libraries as the brushes behave correctly on resize. A formal mechanism for detecting resize events would also be nice; I just copy-pasted the JS handler, I don't know how correct it is.

alexvpickering commented 3 years ago

For anyone looking for this functionality I have also implemented it here using an htmlwidget binding of deck.gl and nebula.gl.

kevinrue commented 3 months ago

Dear Joe (@jcheng5 ) I hope you won't mind me pinging you here that I've just email you '@posit.co' with a potential way of collaborating on this feature request. Just in case it helps bring the email to your attention. Many thanks, Kevin