Repository navigation
sunburst plots: 'plotly_click' event_data only available for root and leafs #1648
Description
Activity
The zoom in/out of plotly sunburst chart is a great feature not seen in other similar sunburst chart implementations, however the missing event data on the zoom make it hard to use it in Shiny app. The workaround above is great using existing information, however if plotly itself can expose the data will be even better.
By the way, for the purpose to get the center piece after chart zoom in/out, maybe it's better to comment out the line of
observe({ clickData(unlist(event_data(event = "plotly_click", source = "sunSource", priority = "event"))) }), because when clicked on last level leaf, the plotly click event fired and was put into clickData. However this kind of click doesn't zoom the chart. With this commented out, the click data only update when non-last level leaf was clicked.User may also need to determine if the plot zoomed in or out by checking if the clicked piece is center, thus need to save last click data to compare.
Thanks for reporting. This is a plotly.js bug. Follow plotly/plotly.js#4338 for progress.
Oh, it's not a plotly.js bug...there is dedicated click event specifically for sunburst,
plotly_sunburstclick. I just added support for that event inevent_data().Reacted by ismirsehregal and dracodocI can understand they want to use a separate event, because when you click on end level leaf the click event is still fired when there is no zoom happening.
@cpsievert , the reason that I want to use this kind of event data is to get the current status of pie chart, especially the current center piece.
With sunburstclick, I can know which piece is clicked, but I need the full click history to calculate which one is center piece:
- clicking on same piece 1st time, zoom in and take it as center if this is not last leaf
- clicking on it immediately in 2nd time, zoom out and center piece will be its parent
- if clicked on last level leaf, nothing happen and take previous center piece
...
This seemed too cumbersome. Do you think there is a better approach for this?
I can know which piece is clicked, but I need the full click history to calculate which one is center piece:
You'll have to store and manage this information using
shiny::reactiveVal()orshiny::reactiveValues(). See this for example https://plotly-r.com/linking-views-with-shiny.html#reactive-valsYes I knew I can store the information. Just I was wondering if there is a better way, or if the information is actually available somewhere in the library, instead of calculating it and hope it don't loose track, once it loose track then everything will mess up...
Just use
plotly_sunburstclickand filter/skip the leaf-clicks?I think that's not enough, clicking on piece A first time will make it to be center, clicking it twice will make its parent to be center. Thus we need to track history to know the status.
- added a commit that references this issue
on Mar 12, 2020 - added a commit that references this issue
on Jun 26, 2022 - added a commit that references this issue
on Jul 4, 2022
Currently it seems that for sunburst plots the 'plotly_click' event_data is only available after clicking the root and leafs of the plot.
I'm wondering whether this behaviour is intentional and inherited by plotly.js or not.
Please see the following example and a workaround I came up with using
onclick, which I first posted here: