plotly / plotly/plotly.R

Targeting/Adding traces in subplot

Offen
#1,899 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Hi - I'm trying to add/change traces in a graph with subplots. Below the example code.

It looks like each subplot becomes one trace (based on playing with the restyle section), but it is unclear to me how to add/remove traces. I changed the addTraces number at the end to 0-3 but it always adds it to the first subplot.

Any help would be appreciated.


data <- tibble(runmonth=c(1,1,1,1,4,4,4,4),variable=c('a','a','b','b','a','a','b','b'),x=c(1:8),y=c(8:1),keyname=paste0('k',c(1:8)))

p <- data %>% group_by(runmonth,variable) %>%
  do(
    p = highlight_key(., ~keyname,group='scattergroup') %>%
      plot_ly(showlegend = FALSE) %>%
      add_markers(
        x = ~x, y = ~y
      )
  ) %>%
  subplot(
    nrows = 2, margin = 0.01,
    shareY = TRUE, shareX = TRUE, titleY = FALSE
  ) %>% toWebGL() %>%
  highlight(
    on = "plotly_selected",
    off = c('plotly_relayout')
  )


ui <- function(id) {
  div(
    actionButton('go','go'),
    plotlyOutput("scattergr")
  )
}

server <- function(input,output,session) {
  
  output$scattergr <- renderPlotly({p})
  
  observeEvent(input$go,{
    plotlyProxy("scattergr", session) %>%
      plotlyProxyInvoke(
        "restyle",
        list(
          'marker.symbol' = list(c(rep('triangle-up',1),'circle'))
        ),
        list(0,1,2,3)
      ) %>%
      plotlyProxyInvoke(
        "addTraces",
        list(
          x = c(50,60),
          y = c(50,60),
          mode = "scatter"
        ),1
      ) %>%
      plotlyProxyInvoke(
        "moveTraces",
        -1,0
      )
  })
  

}

runApp(shinyApp(ui, server))

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Verwende die bereitgestellte Shiny-Reproduktion als Ausgangspunkt und konzentriere dich im Subplot-Beispiel auf die plotlyProxyInvoke-Aufrufe für restyle, addTraces und moveTraces. Bestimme das erwartete Verhalten der Trace-Indizierung für Subplots und ob das Ergebnis eine Code-Korrektur oder eine klarere Dokumentation sein sollte; abgeschlossen ist die Aufgabe, wenn die angeforderten Traces vorhersehbar angesprochen werden können.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.