rstudio / crosstalk

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

Provide a way to set a default selection #16

Open cpsievert opened 7 years ago

cpsievert commented 7 years ago

I'm currently doing this via the defaultValues argument in plotly's highlight() function, and have found it useful for sharing interesting selection states, but this should really be a property of the data, not the plot.

cpsievert commented 7 years ago

In fact, it'd be neat if the selection() method could be used for this...

jcheng5 commented 7 years ago

The problem is that in a non-Shiny world, there's not really a "data" entity in the page at all, is there? There's only the projections of the data onto the plot.

Maybe if you explicitly add a directive to the page that says "Make a selection using these keys and this group".

sd <- SharedData(mtcars)

d3scatter(sd, ...)
d3scatter(sd, ...)
setDefaultSelection(sd$groupName(), row.names(mtcars %>% filter(mpg > 30)))

It's not elegant (imperative instead of declarative, standalone instead of part of the SharedData class) but I don't know where else you would hang this logic?

przemo commented 7 years ago

I guess it would be great to include it in filter functions, e.g. filter_select(default='...')

kent37 commented 7 years ago

Yes please. Setting the initial state is useful for creating a default. For example a map might show many years of data with the current year being the most generally useful and interesting. Initializing checkboxes to show just one year would be helpful.

cpsievert commented 7 years ago

in a non-Shiny world, there's not really a "data" entity in the page at all, is there?

Do we really need one? We have sufficient information to set the relevant value(s) at print time, so why not do something like this?

Note that plotly responds to the callback, but filter_select() does not. Ideally, filter_select() and friends should be able to respond to events as well as set them, but that is kind of a separate issue, so opening #34.

jcheng5 commented 7 years ago

@cpsievert The set_values is along the lines of what I meant by adding a directive to the page.

ewallace commented 7 years ago

Yes, we really need one.

The problem I'm having involves making an interactive plot for 5000+ items in time series, so I can compare 2-10 time series in different colours. The existing default is to plot all of them to start with, and that plot generation crashes my R session in knitR. It would be great to be able to select default values to plot to avoid that.

(Unfortunately I did not understand your set-values.R code).

bwlewis commented 7 years ago

I think that it's possible to initialize widget selections (and filters) without needing to modify the currently lovely minimalist crosstalk interface.

See for example the 2nd and 3rd examples here: https://bwlewis.github.io/crosstool/

That package is still a bit sketchy but manages to initialize a selection without modifying the current crosstalk api.

However, I agree that setting the filter_* UI element state (and corresponding initial filter state) are important to add.

bwlewis commented 7 years ago

Let me add a bit of explanation about my thinking. Although I understand that crosstalk is intentionally opinionated with a bias for selecting and filtering, I plan to use (abuse?) it for other purposes too. I tend to see crosstalk more generically as a communication system with two channels, filter handle and select handle.

jcheng5 commented 7 years ago

I would love a PR for default selection on the filter inputs. Defaults for filters don't have the same difficulties as defaults for selections.

bwlewis commented 7 years ago

yeah, still thinking and experimenting...

On Jul 10, 2017 13:04, "Joe Cheng" notifications@github.com wrote:

I would love a PR for default selection on the filter inputs. Defaults for filters don't have the same difficulties as defaults for selections.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rstudio/crosstalk/issues/16#issuecomment-314170388, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIsnrORG-eRuXGc_1Au1XMOlI8ZfiDpks5sMlmdgaJpZM4K7BzR .

EnricowithR commented 6 years ago

I also think a default selection would be really useful, are there any solutions for that so far?

joelgombin commented 5 years ago

What's the current state of affairs regarding this issue?

abiyug commented 4 years ago

Yes, what is the latest? Can we set "initial state" for filter_select from crosstalk?

jcheng5 commented 4 years ago

@abiyug still in pr form https://github.com/rstudio/crosstalk/pull/70

abiyug commented 4 years ago

Just tested "selected" in flex_dash frame work with devtools version crosstalk_1.0.1.9000. not working here. Any ETA?

jcheng5 commented 4 years ago

You tried installing ”rstudio/crosstalk#70” and it didn’t work? If so, details or a repro case on that PR would be great, thanks.

abiyug commented 4 years ago

70 works!

abiyug commented 4 years ago

"selected" option works with leaflet and DT, but not with plotly any guidance @cpsievert ?

cpsievert commented 4 years ago

You're right, it doesn't appear to work yet with plotly, here's a minimal example:

library(crosstalk)
library(plotly)

mtcars$cyl <- as.factor(mtcars$cyl)
sd <- SharedData$new(mtcars)
filt <- filter_select(
  id = "mag",
  label = "Select cylinder",
  sharedData = sd,
  group = ~cyl,
  multiple = FALSE,
  selected = "6"
)

p <- plot_ly(sd, x = ~wt, y = ~mpg, color = ~cyl) %>% 
  add_markers()

bscols(widths = c(3,9), filt, p)
cthomson8 commented 4 years ago

Has there been any progress on making this work with plotly?

stvrd commented 4 years ago

Kudos for your great work! I agree that the selected argument would be a major improvement, hope to see it soon working with plotly.

abiyug commented 3 years ago

This is such an important feature. Any update?

logan4data commented 3 years ago

Any updates, guidance on this pls,

dexterpante commented 1 year ago

Hello, any updates on this? This is a good improvement if selected option is added.