# How do I retain the information about both the lasso selection and the clicked point?

**URL:** <https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849>\
**Category:** Plotly R\
**Created:** [September 19, 2017, 7:15pm UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849 "2017-09-19T19:15:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![daattali](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/daattali/32/1812_2.png) [@daattali](https://community.plotly.com/u/daattali)\
**Post date:** [September 19, 2017, 7:15pm UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/1 "2017-09-19T19:15:18Z")

</div>

I’m using `plotly::ggplotly()` and I need the user to be able to both select a single point and to select multiple points with brushing. I want both selection options to exist in parallel. The user should be able to click on a point and to lasso select several points, and both of those pieces of information should be recorded.

The problem I’m having is that if I click on a point, then the lasso selection gets reset. But the opposite is not true: if I lasso select and then click on a point, then both are retained.

Here’s a GIF of this issue

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/0/0a04010cd61ed48d00c1aded2292daaec5ede56d.gif)

Here’s my code:

```
library(shiny)
library(plotly)

ui <- fluidPage(
  plotlyOutput("plot"),
  verbatimTextOutput("click"),
  verbatimTextOutput("brush")
)

server <- function(input, output, session) {
  
  nms <- row.names(mtcars)
  
  output$plot <- renderPlotly({
    p <- ggplot(mtcars, aes(x = mpg, y = wt, key = nms)) + geom_point()
    ggplotly(p) %>% layout(dragmode = "lasso")
  })
  
  output$click <- renderPrint({
    d <- event_data("plotly_click")
    if (!is.null(d)) d
  })
  
  output$brush <- renderPrint({
    d <- event_data("plotly_selected")
    if (!is.null(d)) d
  })
  
}

shinyApp(ui, server)

```

To reproduce:

- Click a single point
- Do a lasso selection
- Both are currently visible
- Click a different point
- Now the lasso selection information is gone
- Do a lasso selection again, both are visible again

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jack/32/11_2.png) [@jack](https://community.plotly.com/u/jack)\
**Post date:** [October 15, 2017, 12:24am UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/2 "2017-10-15T00:24:46Z")

</div>

@daattali Thanks for the clean example and GIF. A more expressive API for selecting data is being developed in the plotly.js repo, you can follow the progress here:

[https://github.com/plotly/plotly.js/issues/1848](https://github.com/plotly/plotly.js/issues/1848)

---

<div class="post-metadata">

**Author:** ![MarkvDijk](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@MarkvDijk](https://community.plotly.com/u/MarkvDijk)\
**Post date:** [December 18, 2017, 2:57pm UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/3 "2017-12-18T14:57:06Z")

</div>

@daattali did you by now perhaps discover a way to save a lasso definition as R variable or function? I’ve just came across this post when looking into whether that is even possible or not

---

<div class="post-metadata">

**Author:** ![daattali](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/daattali/32/1812_2.png) [@daattali](https://community.plotly.com/u/daattali)\
**Post date:** [January 20, 2018, 3:27am UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/4 "2018-01-20T03:27:21Z")

</div>

No I did not. I had to modify my requirements and not support it

---

<div class="post-metadata">

**Author:** ![MarkvDijk](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@MarkvDijk](https://community.plotly.com/u/MarkvDijk)\
**Post date:** [January 20, 2018, 12:41pm UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/5 "2018-01-20T12:41:42Z")

</div>

That is a shame. Did you try to talk with cievert about this directly?  
Looks like a very useful tool to me for isolating the same selection region across plots of different files / data sets that are plotted

---

<div class="post-metadata">

**Author:** ![daattali](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/daattali/32/1812_2.png) [@daattali](https://community.plotly.com/u/daattali)\
**Post date:** [January 20, 2018, 6:24pm UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/6 "2018-01-20T18:24:59Z")

</div>

I can’t recall if I spoke to him at the time. I might have. It also might be fixed by now, I haven’t tried. @carson might know better

---

<div class="post-metadata">

**Author:** ![carson](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@carson](https://community.plotly.com/u/carson)\
**Post date:** [January 22, 2018, 2:41pm UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/7 "2018-01-22T14:41:42Z")

</div>

It’s not fixed, and I don’t view it as a high priority problem since you can ‘retain’ selection data via `shiny::reactiveValues()`

---

<div class="post-metadata">

**Author:** ![MarkvDijk](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@MarkvDijk](https://community.plotly.com/u/MarkvDijk)\
**Post date:** [April 10, 2018, 1:49pm UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/8 "2018-04-10T13:49:37Z")

</div>

I could imagine a nice solution like storing a selection region and going through a list of files (data frames) to count the abundance of points in that region, or even multiple region. That way plotly could be used to build manual clustering tools in R shiny.

---

<div class="post-metadata">

**Author:** ![xuzhanyouplotly](https://avatars.discourse-cdn.com/v4/letter/x/b77776/32.png) [@xuzhanyouplotly](https://community.plotly.com/u/xuzhanyouplotly)\
**Post date:** [July 16, 2018, 4:36am UTC](https://community.plotly.com/t/how-do-i-retain-the-information-about-both-the-lasso-selection-and-the-clicked-point/5849/9 "2018-07-16T04:36:59Z")

</div>

Hi Daattali,

Have you solved the problem? I have save issue as you. If yes, can you please post the your solution.

Thank you very much for your help and time in advance!  
Best

zhanyou
