plotly / plotly/plotly.R

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

Open
#2,071 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied R reprex with the plotly update buttons and varying the sensor count. Trace how the updatemenus visibility updates affect the legend, then verify that each button leaves legend items matching the currently visible data and that the existing example no longer shows mixed entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.