plotly / plotly/plotly.R

Update Button badly mixes legenditems of plot (`updatemenus`)

Offen
#2,071 0 Kommentare 0 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´ve come across a weird thing:

I tried the plotly "Update Button" on a plot with a legend. At first everything seems as expected. But as soon as you toggle the plot with help of the update button, the legend is mixed in odd ways. Sometimes the legend even does not correspond to the data at all (e.g. change sensors to 4 in reprex).

example

Heres an example to play around

library(plotly)

df <- data.frame(
  car =    c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), # two cars
  sensor = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5), # with 5 sensors
  x =      c(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2), # sensor data
  y =      c(2, 1, 3, 5, 6, 5, 3, 2, 1, 6, 7, 3, 8, 1, 5, 9, 2, 2, 5, 5)
)

updatemenus <- list(
  list(
    type = "buttons",
    buttons = list(
      list(
        label = "Car 1",
        method = "update",
        args = list(list(visible = list(T, F)))),
      list(
        label = "Car 2",
        method = "update",
        args = list(list(visible = list(F, T))))
    )
  )
)

fig <- plot_ly(type = 'scatter', mode = "lines")
fig <- fig |> add_lines(~x, ~y, data = df[df$car == 1,], name = ~sensor)
fig <- fig |> add_lines(~x, ~y, data = df[df$car == 2,], name = ~sensor, visible = FALSE)
fig <- fig |> layout(
  updatemenus = updatemenus,
  legend = list(title = list(text = "<b> Sensor </b>"))
  )

fig

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

Beginne damit, das bereitgestellte R-reprex mit den plotly-Update-Schaltflächen auszuführen und dabei die Sensoranzahl zu variieren. Verfolge, wie sich die Sichtbarkeitsaktualisierungen von updatemenus auf die Legende auswirken. Überprüfe anschließend, dass jede Schaltfläche Legendeneinträge hinterlässt, die den aktuell sichtbaren Daten entsprechen, und dass das bestehende Beispiel keine gemischten Einträge mehr anzeigt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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