Skip to content

Mix of "legendonly" and FALSE on updatemenus visibility update #2935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
epimedplotly opened this issue Aug 21, 2018 · 2 comments
Closed

Mix of "legendonly" and FALSE on updatemenus visibility update #2935

epimedplotly opened this issue Aug 21, 2018 · 2 comments

Comments

@epimedplotly
Copy link

epimedplotly commented Aug 21, 2018

hey there,

There is a plotly's feature that is not working correctly. Im not sure if it is a bug or just a non-implemented feature really so I'll let you decide. Im an R user so I will post a example in R code here. I don't know another language for which plotly works like Java so sorry about that.

On plotly, trace visibility accepts 3 different values. TRUE, FALSE and "legendonly". It is also possible to edit trace visibility using updatemenus, like buttons and dropdownmenus. The problem is that when using updatemenus to update trace visibility, it is possible to mix TRUE and FALSE, TRUE and "legendonly" but mixing FALSE and "legendonly" does not work correctly. When i do mix the last two options, FALSE is recognized as TRUE. I didn't see any example on plotly website using this specific mix so I'm not sure it was suposed to work.

Here goes a link to a plot in which that problem happens and the R code to generate it:

https://plot.ly/~EpimedSolutions/47/#/

library(plotly)

x0 <- rnorm(400, mean=2, sd=0.4)
y0 <- rnorm(400, mean=2, sd=0.4)
x1 <- rnorm(400, mean=3, sd=0.6)
y1 <- rnorm(400, mean=6, sd=0.4)
x2 <- rnorm(400, mean=4, sd=0.2)
y2 <- rnorm(400, mean=4, sd=0.4)

shapes components

cluster0 = list(
type = 'circle',
xref ='x', yref='y',
x0=min(x0), y0=min(y0),
x1=max(x0), y1=max(y0),
opacity=0.25,
line = list(color="#835AF1"),
fillcolor="#835AF1")

cluster1 = list(
type = 'circle',
xref ='x', yref='y',
x0=min(x1), y0=min(y1),
x1=max(x1), y1=max(y1),
opacity=0.25,
line = list(color="#7FA6EE"),
fillcolor="#7FA6EE")

cluster2 = list(
type = 'circle',
xref ='x', yref='y',
x0=min(x2), y0=min(y2),
x1=max(x2), y1=max(y2),
opacity=0.25,
line = list(color="#B8F7D4"),
fillcolor="#B8F7D4")

updatemenus component

updatemenus <- list(
list(
active = -1,
type = 'buttons',
buttons = list(

  list(
    label = "All legendonly",
    method = "update",
    args = list(list(visible = c('legendonly','legendonly','legendonly')))),
  
  list(
    label = "Cluster 0 F",
    method = "update",
    args = list(list(visible = c(F,'legendonly','legendonly')))),
  
  list(
    label = "Cluster 1 F",
    method = "update",
    args = list(list(visible = c('legendonly',F,'legendonly')))),
  
  list(
    label = "Cluster 2 F",
    method = "update",
    args = list(list(visible = c('legendonly','legendonly',F)))),
  
  list(
    label = "All T",
    method = "update",
    args = list(list(visible = list(T,T,T))))
)

)
)

p <- plot_ly(type = 'scatter', mode='markers') %>%
add_trace(x=x0, y=y0, mode='markers', marker=list(color='#835AF1')) %>%
add_trace(x=x1, y=y1, mode='markers', marker=list(color='#7FA6EE')) %>%
add_trace(x=x2, y=y2, mode='markers', marker=list(color='#B8F7D4')) %>%
layout(title = "Highlight Clusters",
updatemenus = updatemenus)
p

Thanks for your attention.

@alexcjohnson
Copy link
Collaborator

The issue is true and false are supposed to be boolean values, but somehow by the time they make it here you have the string 'FALSE' which is invalid so we revert to the default value (true). Not sure if this is an issue with the R API or something in your code - you do have the correct true in the 'All T' button which makes me think perhaps it's a problem with the R API and mixed-type arrays? Anyway I would open an issue over at https://github.com/ropensci/plotly

@epimedplotly
Copy link
Author

Alright, Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants