plotly / plotly/plotly.R

geom_sina plot doesn't show when linked to another plot via brushing in Shiny

Ouverte
#1,858 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
R
Étoiles
2.7k
Forks
641
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Hello,

I'm attempting to link points from a geom_sina object to another plot (it will be a bar-plot but for now, I just have a scatterplot to illustrate the problem). The issue is that when I put the "key=key" aesthetic into geom_sina, the plot doesn't show up.The plot will show up if I remove the "key=key" aesthetic, but then I have no means by which to connect the plots. I think this might be a bug given that this works fine with geom_point.

library(plotly)
library(shiny)
library(tidyverse)

df = diamonds 
df = df[sample(1:nrow(df), size=1000, replace=FALSE), ] %>%
  rownames_to_column("key")

server <- function(input, output) {
  output$my_points <- renderPlotly({
    p = ggplot(df, aes(x=cut, y=price, label=clarity)) +
      coord_flip() +
      ggforce::geom_sina(aes(color=carat, key=key), alpha=.2) +
      # gggforce::geom_sina(aes(color=carat), alpha=.2) + # this will make the plot show up, but doesn't link it to the other
      # geom_point(aes(color=carat, key=key), alpha=.2) + # using geom_point works here
      theme_light()
    
    ggplotly(p, source="ggplotly_points")
  })
  
  selected_values <- reactive({
    brush <- event_data("plotly_click", source="ggplotly_points")
    if (is.null(brush)) {
      TRUE
    } else {
      df$key == (brush$pointNumber + 1)
    }
  })
  output$scatter <- renderPlotly({
    df %>%
      filter(selected_values()) %>%
      plot_ly(
        x = ~carat, 
        y = ~price, 
        alpha = 0.2
      ) %>%
      toWebGL()
  })
}

ui <- fluidPage(
  plotlyOutput("my_points"),
  plotlyOutput("scatter")
)


shinyApp(ui, server)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par exécuter l’exemple R Shiny fourni et comparez le cas ggforce::geom_sina avec le cas fonctionnel geom_point. Suivez la conversion ggplotly et la gestion de key afin d’identifier pourquoi l’ajout de key=key empêche le rendu du graphique ; c’est terminé lorsque le graphique sina s’affiche et que ses points cliqués renvoient toujours vers le second graphique.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
r
Domaine
data-visualization
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.