rstudio / crosstalk

Inter-htmlwidget communication for R (with and without Shiny)
http://rstudio.github.io/crosstalk
Other
289 stars 53 forks source link

Legend disspaeres when checkboxes are selected #88

Open yuliaUU opened 4 years ago

yuliaUU commented 4 years ago

Hi, I wrote a code that filters the graph based on some inputs that are not part of the legend

library(plotly)
library(crosstalk)
# shared data object
shared_us <- SharedData$new(mtcars, key = ~cyl)

# scatterplot of housing price index against homeownership
p17 <- shared_us %>%
  plot_ly(x = ~mpg, y = ~hp, color = ~gear, height = 400) %>%
  add_markers()

# add a column of checkboxes for region to the left of the plot
bscols(widths = c(3, NA),
  filter_checkbox(id = "cyl", label = "Cylinders", sharedData = shared_us, group = ~cyl),
  p17
)

so, at first, none checkboxes are selected, and everything is showing nicely: image However, when I select one of the checkboxes, the legend disappears, I am not sure why. I also was wondering whether there is an option to have the checkboxes checked? ( rather than them being unchecked)

gilmeriken commented 4 years ago

Adding to this one, relevant to use of filter_checkbox.

Since the default is to have all unfiltered data (I think), is there a way to have all checkboxes checked as the initial setting?

jcheng5 commented 4 years ago

@cpsievert Is the legend thing a plotly issue?

@gilmeriken I guess it depends--is it more likely that people want to see one item at a time (in which case all unchecked is a better default) or to exclude one item at a time (in which case all checked is better)? I'm guessing it's the former.

yuliaUU commented 4 years ago

I just have an issue that although non of the boxes checked: the plot shows all points ( which does not make sense: I would expect no points on the graph if boxes are unchecked)

cpsievert commented 4 years ago

@jcheng5 looks like it

gilmeriken commented 4 years ago

@jcheng5

For me, it's the latter (start with all boxes checked, then begin unchecking), but I understand I may be in the minority.

"Check All" or "Uncheck All" options as single checkboxes would be a nice enhancement. Is this possible today?

jcheng5 commented 4 years ago

@yuliaUU Hmmm, I can see why you would think that. It's sort of common on the web though that none-checked means "don't filter" (see example below). Is this just surprising to you, or do you actually want/need no points on the graph?

@gilmeriken That would certainly help. As would https://github.com/rstudio/crosstalk/pull/83 (on my backlog since April, sorry, I suck), which would at least let you pre-check them all when appropriate.

image