crosstalk icon indicating copy to clipboard operation
crosstalk copied to clipboard

Provide a way to set a default selection

Open cpsievert opened this issue 8 years ago • 25 comments

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 avatar Nov 23 '16 20:11 cpsievert

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

cpsievert avatar Nov 23 '16 20:11 cpsievert

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?

jcheng5 avatar Dec 14 '16 22:12 jcheng5

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

przemo avatar Feb 23 '17 22:02 przemo

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.

kent37 avatar Mar 19 '17 11:03 kent37

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.

cpsievert avatar Apr 12 '17 22:04 cpsievert

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

jcheng5 avatar Apr 13 '17 16:04 jcheng5

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).

ewallace avatar Jun 30 '17 14:06 ewallace

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 avatar Jul 10 '17 07:07 bwlewis

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.

bwlewis avatar Jul 10 '17 14:07 bwlewis

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.

jcheng5 avatar Jul 10 '17 17:07 jcheng5

yeah, still thinking and experimenting...

On Jul 10, 2017 13:04, "Joe Cheng" [email protected] 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 .

bwlewis avatar Jul 10 '17 17:07 bwlewis

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

EnricowithR avatar Sep 10 '17 06:09 EnricowithR

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

joelgombin avatar Nov 12 '18 14:11 joelgombin

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

abiyug avatar Nov 26 '19 16:11 abiyug

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

jcheng5 avatar Nov 26 '19 16:11 jcheng5

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

abiyug avatar Nov 26 '19 16:11 abiyug

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.

jcheng5 avatar Nov 26 '19 16:11 jcheng5

#70 works!

abiyug avatar Nov 26 '19 17:11 abiyug

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

abiyug avatar Nov 26 '19 18:11 abiyug

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)

cpsievert avatar Nov 26 '19 18:11 cpsievert

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

cthomson8 avatar May 25 '20 12:05 cthomson8

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

stvrd avatar Aug 04 '20 09:08 stvrd

This is such an important feature. Any update?

abiyug avatar Dec 04 '20 20:12 abiyug

Any updates, guidance on this pls,

logan4data avatar Apr 19 '21 11:04 logan4data

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

dexterpante avatar Jul 12 '23 03:07 dexterpante