Skip to content
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

Provide a way to set a default selection #16

Open
cpsievert opened this issue Nov 23, 2016 · 25 comments
Open

Provide a way to set a default selection #16

cpsievert opened this issue Nov 23, 2016 · 25 comments

Comments

@cpsievert
Copy link
Contributor

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
Copy link
Contributor Author

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

@jcheng5
Copy link
Member

jcheng5 commented Dec 14, 2016

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
Copy link

przemo commented Feb 23, 2017

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

@kent37
Copy link
Contributor

kent37 commented Mar 19, 2017

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
Copy link
Contributor Author

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
Copy link
Member

jcheng5 commented Apr 13, 2017

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

@ewallace
Copy link

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
Copy link

bwlewis commented Jul 10, 2017

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
Copy link

bwlewis commented Jul 10, 2017

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
Copy link
Member

jcheng5 commented Jul 10, 2017

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
Copy link

bwlewis commented Jul 10, 2017 via email

@EnricowithR
Copy link

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

@joelgombin
Copy link

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

@abiyug
Copy link

abiyug commented Nov 26, 2019

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

@jcheng5
Copy link
Member

jcheng5 commented Nov 26, 2019

@abiyug still in pr form #70

@abiyug
Copy link

abiyug commented Nov 26, 2019

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

@jcheng5
Copy link
Member

jcheng5 commented Nov 26, 2019

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
Copy link

abiyug commented Nov 26, 2019

#70 works!

@abiyug
Copy link

abiyug commented Nov 26, 2019

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

@cpsievert
Copy link
Contributor Author

cpsievert commented Nov 26, 2019

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
Copy link

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

@stvrd
Copy link

stvrd commented Aug 4, 2020

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
Copy link

abiyug commented Dec 4, 2020

This is such an important feature. Any update?

@logan4data
Copy link

Any updates, guidance on this pls,

@dexterpante
Copy link

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

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