plotly / plotly/plotly.R

distinguish links and nodes in sankeyPlot using event_data

未关闭
#1,752 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

enhancement
主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

I am building a sankey plot using plotly package with R within a Shiny application.
At some point, I use event_data function which returns an index pointNumber which is an integer ranging from 0 to the number of pairwise nodes relationships.
When performing sankeyPlot in plotly you have to specify the node and link arguments. The problem is that pointNumber provides an index which I cannot distinguish between the node or the link.
I would like the app could identify if the user clicks on a node or on a link.

Here is a toy example. Note that when clicking on node "A", pointNumber returns 0, and the same when clicking on link connecting node "A" and node "B".

library(plotly); library(shiny)
ui <- fluidPage(
  plotlyOutput("plot"),
  verbatimTextOutput("index")
)
server <- function(input, output){
  output$index <- renderPrint({
    event_data("plotly_click", source="sankeyPlot")
  })
  output$plot <- renderPlotly({
    plot_ly(
      source = "sankeyPlot",
      type = "sankey",
      arrangement = "fixed",
      node = list(label = c("A","B","C","D"), hoverinfo="none"),
      link = list(source=c(0,0,1,2), target=c(1,2,3,3), value=c(2,5,2,1), hoverinfo="none")
    )
  })
}
shinyApp(ui, server)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从使用 event_data("plotly_click") 的简单 Shiny 示例开始,检查在 sankey 图上点击节点和链接时返回的 pointNumber。跟踪 sankeyPlot 事件的表示方式,并确定返回的数据如何区分被点击的元素。当应用能够可靠地识别点击的目标是节点还是链接时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。