Skip to content Skip to sidebar Skip to footer

Selecting A Default Value In An R Plotly Plot Using A Selectize Box Via Crosstalk In R, Using Static Html Not Shiny

In an Rmarkdown html document, how does one select a default value for a crosstalk::filter_select dropdown that will work with plotly plots? E.g., in the example below, to have jus

Solution 1:

You can directly manipulate the selectize boxes that crosstalk filter_select ouputs using javascript, the trick is triggering it on load like so:

```{js}
function filter_default() {
    document.getElementById("filter").getElementsByClassName("selectized")[0].selectize.setValue("a", false);
}
window.onload = filter_default;
```

Solution 2:

The problem appeared to have been solved here by installing ”rstudio/crosstalk#70”. Then you will be able to use the select option

Solution 3:

Just to complement the accepted answer, which did function in the RStudio viewer in my case, but not in Chrome/Edge/IE/Firefox: the jQuery event Document.ready solved the problem (idea from this thread)

$(document).ready(function() {
    document.getElementById("filter").getElementsByClassName("selectized")[0].selectize.setValue("a", false);
});

Post a Comment for "Selecting A Default Value In An R Plotly Plot Using A Selectize Box Via Crosstalk In R, Using Static Html Not Shiny"