close
The Wayback Machine - https://web.archive.org/web/20201217182114/https://github.com/ropensci/plotly/issues/1822
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coupling tooltips on hover between subplots using r and plotly #1822

Open
ssinari opened this issue Jul 22, 2020 · 0 comments
Open

Coupling tooltips on hover between subplots using r and plotly #1822

ssinari opened this issue Jul 22, 2020 · 0 comments

Comments

@ssinari
Copy link

@ssinari ssinari commented Jul 22, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.