Coupling tooltips on hover between subplots using r and plotly
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
I would like to do a plot like this one: https://www.somesolvedproblems.com/2020/03/how-to-link-plotly-events-between-plots.html
Here is what I have tried:
library(tidyverse)
library(htmlwidgets)
library(ggplot2)
library(plotly)
library(shiny)
x <- seq(0,1, 0.001)
y <- sin(2*pi*x)
z <- cos(2*pi*x)
df <- data.frame(x = x, y = y, z = z)
p <- ggplot(df, aes(x, y)) + geom_line()
q <- ggplot(df, aes(x, z)) + geom_line()
r <- subplot(p
, q
, nrows =1
, titleX = FALSE
, titleY = FALSE)
r$elementId <- "rt"
s <- r %>%
onRender("
function(el) {
el.on('plotly_hover', function (eventdata){
console.log(eventdata.xvals);
Plotly.Fx.hover('rt',
[
{ curveNumber: 0, pointNumber:eventdata.points[0].pointNumber },
{ curveNumber: 1, pointNumber:eventdata.points[0].pointNumber },
]
);
}
")
with hints from: https://community.plotly.com/t/coupling-hover-events-for-side-by-side-subplots/2049 and https://plotly-r.com/js-event-handlers.html
However, this does not work yet. Primarily, because of my lack of understanding of the javascript issues. Is such bidirectional trigger possible? Can this be done using plotly package and related tools such as htmlwidgets and htmltools package for r? Thanks.
This issue is also posted on stackoverflow:
Link to issue on Stackoverflow
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
The issue provides no repository file or test entry point. Start by reproducing the R example with subplot(), htmlwidgets::onRender(), and Plotly.Fx.hover(), then define a supported bidirectional hover behavior and an executable example or test as the done criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100