# Is this a bug in dropdown events?

**URL:** https://community.plotly.com/t/is-this-a-bug-in-dropdown-events/6226
**Category:** Plotly R
**Created:** [October 11, 2017, 5:35pm UTC](https://community.plotly.com/t/is-this-a-bug-in-dropdown-events/6226 "2017-10-11T17:35:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![erudie](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@erudie](https://community.plotly.com/u/erudie)
#### Post date: [October 11, 2017, 5:35pm UTC](https://community.plotly.com/t/is-this-a-bug-in-dropdown-events/6226/1 "2017-10-11T17:35:07Z")

</div>

I have replicated the unexpected behavior using mtcars.  
I want to be able to toggle between Numbers and Percents using a dropdown, but the “Number” from the previously visible plot of the second cateogry seems to get carried over when I toggle to “Percent.”

```
mtcars %>%
  mutate(vs = ifelse(vs == 0, "V", "S"), am = ifelse(am == 0, "auto", "manual")) %>%
  group_by(vs, am) %>%
  summarise(total = n(), num_big = sum(wt > 2.5),
            percent_big = (sum(wt > 2.5) / n())*100) %>%
  plot_ly(x = ~vs, color = ~am, colors = c("green", "blue")) %>%
  add_bars(y = ~num_big, name = "Number Big Cars", text = ~num_big) %>%
  add_bars(y = ~percent_big, name = "Percent Big Cars", text = ~percent_big, visible = F) %>%
  layout(title = "Big Cars per Category",
         showlegend = T,
         barmode = "group",
         yaxis = list(title = ""),
         updatemenus = list(
           list(
             buttons = list(
               list(method = "restyle",
                    args = list(
                      list("visible", list(TRUE, FALSE))),
                    label = "Number Big Cars"),
               list(method = "restyle",
                    args = list("visible", list(FALSE, TRUE)),
                    label = "Percent Big Cars")))
         ))

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/0/0ed9a2cf44adcab12608bb418e25dc31804faa5c.jpg)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/d/d50ba58868d17204b22e4e90e75fb8828b11e77f.jpg)

Surprisingly, the issue is somewhat fixed by adding an extra “FALSE, TRUE” in the middle of the second “visible” arg. But I still can’t toggle back to “Number.”

```
mtcars %>%
  mutate(vs = ifelse(vs == 0, "V", "S"), am = ifelse(am == 0, "auto", "manual")) %>%
  group_by(vs, am) %>%
  summarise(total = n(), num_big = sum(wt > 2.5),
            percent_big = (sum(wt > 2.5) / n())*100) %>%
  plot_ly(x = ~vs, color = ~am, colors = c("green", "blue")) %>%
  add_bars(y = ~num_big, name = "Number Big Cars", text = ~num_big) %>%
  add_bars(y = ~percent_big, name = "Percent Big Cars", text = ~percent_big, visible = F) %>%
  layout(title = "Big Cars per Category",
         showlegend = T,
         barmode = "group",
         yaxis = list(title = ""),
         updatemenus = list(
           list(
             buttons = list(
               list(method = "restyle",
                    args = list(
                      list("visible", list(TRUE, FALSE))),
                    label = "Number Big Cars"),
               list(method = "restyle",
                    args = list("visible", list(FALSE, FALSE, TRUE, TRUE)),
                    label = "Percent Big Cars")))
         ))

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/5/5fd666d038c937c77522d2ad582212f41f035208.jpg)

What’s going on? How can I toggle back to Number?  
Any tips much appreciated.  
Many thanks,  
Emma

---

<div class="post-metadata">

### Author: ![bcd](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@bcd](https://community.plotly.com/u/bcd)
#### Post date: [October 11, 2017, 6:35pm UTC](https://community.plotly.com/t/is-this-a-bug-in-dropdown-events/6226/2 "2017-10-11T18:35:36Z")

</div>

Hey @erudie,

try:

```
updatemenus = list(
           list(
             buttons = list(
               list(method = "restyle",
                    args = list("visible", list(TRUE, TRUE, FALSE, FALSE)),
                    label = "Number Big Cars"),
               list(method = "restyle",
                    args = list("visible", list(FALSE, FALSE, TRUE, TRUE)),
                    label = "Percent Big Cars")))
         ))
```

---

<div class="post-metadata">

### Author: ![erudie](https://avatars.discourse-cdn.com/v4/letter/e/a87d85/32.png) [@erudie](https://community.plotly.com/u/erudie)
#### Post date: [October 11, 2017, 7:55pm UTC](https://community.plotly.com/t/is-this-a-bug-in-dropdown-events/6226/3 "2017-10-11T19:55:13Z")

</div>

Ah! This works!  
I had already tried that on my personal use-case but it didn’t work because I had a misplaced parenthesis. Oh well.  
Thanks for the fast reply!!  
-Emma
