crosstalk
                                
                                 crosstalk copied to clipboard
                                
                                    crosstalk copied to clipboard
                            
                            
                            
                        Provide a way to set a default selection
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.
In fact, it'd be neat if the selection() method could be used for this...
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?
I guess it would be great to include it in filter functions, e.g. filter_select(default='...')
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.
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 The set_values is along the lines of what I meant by adding a directive to the page.
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).
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.
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.
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.
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 .
I also think a default selection would be really useful, are there any solutions for that so far?
What's the current state of affairs regarding this issue?
Yes, what is the latest? Can we set "initial state" for filter_select from crosstalk?
@abiyug still in pr form https://github.com/rstudio/crosstalk/pull/70
Just tested "selected" in flex_dash frame work with devtools version crosstalk_1.0.1.9000. not working here. Any ETA?
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.
#70 works!
"selected" option works with leaflet and DT, but not with plotly any guidance @cpsievert ?
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)
Has there been any progress on making this work with plotly?
Kudos for your great work! I agree that the selected argument would be a major improvement, hope to see it soon working with plotly.
This is such an important feature. Any update?
Any updates, guidance on this pls,
Hello, any updates on this? This is a good improvement if selected option is added.