{"action":"created","issue":{"url":"https://api.github.com/repos/ropensci/plotly/issues/1248","repository_url":"https://api.github.com/repos/ropensci/plotly","labels_url":"https://api.github.com/repos/ropensci/plotly/issues/1248/labels{/name}","comments_url":"https://api.github.com/repos/ropensci/plotly/issues/1248/comments","events_url":"https://api.github.com/repos/ropensci/plotly/issues/1248/events","html_url":"https://github.com/ropensci/plotly/issues/1248","id":320063235,"node_id":"MDU6SXNzdWUzMjAwNjMyMzU=","number":1248,"title":"Feature Request: Remove traces by name using plotlyProxy()","user":{"login":"msummersgill","id":19575728,"node_id":"MDQ6VXNlcjE5NTc1NzI4","avatar_url":"https://avatars3.githubusercontent.com/u/19575728?v=4","gravatar_id":"","url":"https://api.github.com/users/msummersgill","html_url":"https://github.com/msummersgill","followers_url":"https://api.github.com/users/msummersgill/followers","following_url":"https://api.github.com/users/msummersgill/following{/other_user}","gists_url":"https://api.github.com/users/msummersgill/gists{/gist_id}","starred_url":"https://api.github.com/users/msummersgill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msummersgill/subscriptions","organizations_url":"https://api.github.com/users/msummersgill/orgs","repos_url":"https://api.github.com/users/msummersgill/repos","events_url":"https://api.github.com/users/msummersgill/events{/privacy}","received_events_url":"https://api.github.com/users/msummersgill/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-05-03T20:12:16Z","updated_at":"2018-09-14T08:42:25Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I originally posted this as a long shot [stack overflow question](https://stackoverflow.com/questions/50138568/removing-traces-by-name-using-plotlyproxy-or-accessing-output-schema-in-reactiv), but I'm suspecting the functionality I'm looking for might require some new code.\r\n\r\nWhen using `plotlyProxy()`, adding new traces with a `name` attribute is very straightforward. However, removing a trace by name does not appear to be possible. Reviewing the [plotly.Js function reference](https://plot.ly/javascript/plotlyjs-function-reference/), it appears that the JavaScript methods exclusively use indices, so this might require an additional javascript method to match names to trace numbers.\r\n\r\nThe example shiny app below illustrates the functionality I'm looking for. In the screenshot, when the user clicked the \"Remove Trace\" button, trace `xxx` would be removed.\r\n\r\n![plotlyproxy](https://user-images.githubusercontent.com/19575728/39599049-22454a12-4ee0-11e8-8339-7522e402a3b4.PNG)\r\n```r\r\nlibrary(shiny)\r\nlibrary(plotly)\r\n\r\nui <- fluidPage(\r\n  textInput(\"TraceName\", \"Trace Name\"),\r\n  actionButton(\"Add\",\"Add Trace\"),\r\n  actionButton(\"Remove\",\"Remove Trace\"),\r\n  plotlyOutput(\"MyPlot\")\r\n)\r\n\r\nserver <- function(input,output,session) {\r\n\r\n  ## Creating the plot\r\n  output$MyPlot <- renderPlotly({\r\n    plot_ly() %>%\r\n      layout(showlegend  = TRUE)\r\n  })\r\n\r\n  ## Adding traces is smooth sailing\r\n  observeEvent(input$Add,{\r\n    plotlyProxy(\"MyPlot\", session) %>%\r\n      plotlyProxyInvoke(\"addTraces\", list(x = rnorm(10),y = rnorm(10),\r\n                                          type = \"scatter\",mode = \"markers\",\r\n                                          name = input$TraceName))\r\n  })\r\n\r\n  ## Ideal Solution (that does not work)\r\n  observeEvent(input$Remove,{\r\n    plotlyProxy(\"MyPlot\", session) %>%\r\n      plotlyProxyInvoke(\"deleteTraces\", input$TraceName)\r\n  })\r\n\r\n}\r\n```\r\n***\r\n\r\nJavaScript is not my strong suit, but it seems like one way to support this would be to add a new method in [htmlwidgets/plotly.js](https://github.com/ropensci/plotly/blob/master/inst/htmlwidgets/plotly.js), perhaps called `traceNamesToIDs`. Then, the steps might look something like the following.\r\n\r\n```r\r\nDeleteTraceNames <- c(\"xxx\")\r\nMyPlotProxy <- plotlyProxy(\"MyPlot\", session)\r\nTraceNumberList <- plotlyProxyInvoke(MyPlotProxy, \"traceNamesToIds\", )) ## Returns c(0)\r\nplotlyProxyInvoke(MyPlotProxy ,\"deleteTraces\", TraceNumberList )\r\n```\r\nI'm not quite sure, but as I read through htmlwidgets/plotly.js, it seems like there is already some very similar functionality in the codebase to support Cross Talk integration.\r\n\r\nAlternatively, if the `deleteTraces` method could be modified to directly accept names as a character input, that seems like the most intuitive usage from a user standpoint. However, this might result in breaking changes for users who wrote code based on trace numbers depending on the details of implementation.\r\n\r\n```r\r\nplotlyProxy(\"MyPlot\", session) %>%\r\n    plotlyProxyInvoke(\"deleteTraces\", c(\"xxx\"))\r\n```\r\nIf some implementation of this functionality could be added in future versions, I think it could make a substantial difference in the ease of use!"},"comment":{"url":"https://api.github.com/repos/ropensci/plotly/issues/comments/421275920","html_url":"https://github.com/ropensci/plotly/issues/1248#issuecomment-421275920","issue_url":"https://api.github.com/repos/ropensci/plotly/issues/1248","id":421275920,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMTI3NTkyMA==","user":{"login":"madmark81","id":29946999,"node_id":"MDQ6VXNlcjI5OTQ2OTk5","avatar_url":"https://avatars1.githubusercontent.com/u/29946999?v=4","gravatar_id":"","url":"https://api.github.com/users/madmark81","html_url":"https://github.com/madmark81","followers_url":"https://api.github.com/users/madmark81/followers","following_url":"https://api.github.com/users/madmark81/following{/other_user}","gists_url":"https://api.github.com/users/madmark81/gists{/gist_id}","starred_url":"https://api.github.com/users/madmark81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madmark81/subscriptions","organizations_url":"https://api.github.com/users/madmark81/orgs","repos_url":"https://api.github.com/users/madmark81/repos","events_url":"https://api.github.com/users/madmark81/events{/privacy}","received_events_url":"https://api.github.com/users/madmark81/received_events","type":"User","site_admin":false},"created_at":"2018-09-14T08:42:25Z","updated_at":"2018-09-14T08:42:25Z","author_association":"NONE","body":"Any news on making this reality?\r\n"}}
{"actor":{"display_login":"madmark81"}}