distinguish links and nodes in sankeyPlot using event_data
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the toy Shiny example using event_data("plotly_click") on the sankey plot and inspect the returned pointNumber for node and link clicks. Trace how sankeyPlot events are represented and determine how the returned data can distinguish the clicked element. Done means the app can reliably identify whether a click targets a node or a link.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100