Coupling tooltips on hover between subplots using r and plotly
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- R
- Estrellas
- 2.7k
- Forks
- 641
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
El issue no proporciona ningún archivo del repositorio ni ningún punto de entrada de prueba. Empieza reproduciendo el ejemplo de R con subplot(), htmlwidgets::onRender() y Plotly.Fx.hover(), y después define un comportamiento de hover bidireccional compatible y un ejemplo o prueba ejecutable como criterios de finalización.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, r
- Área
- data-visualization
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100