Feature Request: Remove traces by name using plotlyProxy()
まだ誰も着手していません。
- 主要言語
- R
- スター
- 2.7k
- フォーク
- 641
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I originally posted this as a long shot stack overflow question, but I'm suspecting the functionality I'm looking for might require some new code.
When 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, it appears that the JavaScript methods exclusively use indices, so this might require an additional javascript method to match names to trace numbers.
The 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.
library(shiny)
library(plotly)
ui <- fluidPage(
textInput("TraceName", "Trace Name"),
actionButton("Add","Add Trace"),
actionButton("Remove","Remove Trace"),
plotlyOutput("MyPlot")
)
server <- function(input,output,session) {
## Creating the plot
output$MyPlot <- renderPlotly({
plot_ly() %>%
layout(showlegend = TRUE)
})
## Adding traces is smooth sailing
observeEvent(input$Add,{
plotlyProxy("MyPlot", session) %>%
plotlyProxyInvoke("addTraces", list(x = rnorm(10),y = rnorm(10),
type = "scatter",mode = "markers",
name = input$TraceName))
})
## Ideal Solution (that does not work)
observeEvent(input$Remove,{
plotlyProxy("MyPlot", session) %>%
plotlyProxyInvoke("deleteTraces", input$TraceName)
})
}
JavaScript 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, perhaps called traceNamesToIDs. Then, the steps might look something like the following.
DeleteTraceNames <- c("xxx")
MyPlotProxy <- plotlyProxy("MyPlot", session)
TraceNumberList <- plotlyProxyInvoke(MyPlotProxy, "traceNamesToIds", )) ## Returns c(0)
plotlyProxyInvoke(MyPlotProxy ,"deleteTraces", TraceNumberList )
I'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.
Alternatively, 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.
plotlyProxy("MyPlot", session) %>%
plotlyProxyInvoke("deleteTraces", c("xxx"))
If some implementation of this functionality could be added in future versions, I think it could make a substantial difference in the ease of use!
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず inst/htmlwidgets/plotly.js を読み、特に plotlyProxyInvoke の処理と、issue で言及されている既存の Cross Talk 関連機能を確認します。次に、提供されている Shiny アプリを再現し、deleteTraces の trace 名による動作と trace インデックスによる動作を比較します。選択した trace を名前で削除でき、既存のインデックスベースの使用方法を壊さなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, r
- 領域
- data-visualization
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100