Update Button badly mixes legenditems of plot (`updatemenus`)
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).

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
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Ö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