Do you need to have "js" package installed in R to run javascript code chunks in an R flexdashboard using crosstalk?
Example code: (taken from another post)
---
output:
html_document
---
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(plotly)
# example data
dat <- tibble::tribble(~filterBy, ~x, ~y,
"a", 1, 1,
"b", 2, 1,
"a", 1, 2,
"b", 2, 2,
"a", 1, 3,
"b", 2, 3,
"a", 1, 2,
"b", 2, 3,
"c", 3, 1,
"c", 3, 2,
"c", 3, 3
)
# initializing a crosstalk shared data object
plotdat <- highlight_key(dat)
# Filter dropdown
question_filter <- crosstalk::filter_select(
"lantern", "Select a group to examine",
plotdat, ~filterBy, multiple = F
)
# Plotting:
plot <- plot_ly( plotdat,
x = ~x, y = ~y, text = ~filterBy, mode = "markers+text",
textposition = "top", hoverinfo = "x+y"
)
```
```{js}
function filter_default() {
document.getElementById("lantern").getElementsByClassName("selectized")
[0].selectize.setValue("bulb", false);
}
window.onload = filter_default;
```
The filter_default is not working in my code, however the "js" library will not load. Could this be the issue?