plotly / plotly/plotly.R

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

Aperta
#1,858 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
R
Stelle
2.7k
Fork
641
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo l’esempio R Shiny fornito e confronta il caso ggforce::geom_sina con il caso funzionante geom_point. Traccia la conversion ggplotly e la gestione di key per identificare perché l’aggiunta di key=key impedisce il rendering del grafico; il lavoro è completato quando il grafico sina viene visualizzato e i suoi punti cliccati continuano a collegarsi al secondo grafico.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
r
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.