crosstalk
crosstalk copied to clipboard
Bug with filter_slider and dates
I encountered an obscure error with filter_slider
applied to an object of class Date
.
Here is a minimal example to reproduce it: https://gist.github.com/bhogan-mitre/81d1eaffc56deb342e8dbff7f2d3194f
If the filter_slider
of Date
comes second in the list of inputs, it throws an error:
Uncaught TypeError: Cannot read property 'utc' of undefined
If the inputs are reversed so the filter_slider
is first, it renders fine.
filter_slider("date", "Date", shared_mtcars, ~date, width = "100%")
filter_checkbox("cyl", "Cylinders", shared_mtcars, ~cyl, inline = TRUE)
Note that I am using this with flexdashboard
, so that may be a contributing factor as well.
I am having the same issue, did you find any solutions?
No, I have not found any solution other than the workaround described above to reorder the inputs.
Any other insights on how to minimize filter_slider issues with dates? I've been running into a lot of trouble with them -- see here.
Think I've come across a different, but related error. I have a filter_slider using dates. When I run the R chunks, it renders and functions correctly. However, once I knit to HTML the slider becomes an empty box. I have tried reordering my filters, only keeping the slider, moving into and out of the same R chunk, but all have given me the same results.
I have encountered the same error and have discovered that it is an html dependency issue.
The strftime js library is called after the crosstalk library. Changing the order of the html
(before) <script src="site_libs/strftime-0.9.2/strftime-min.js"></script>
(after) <script src="site_libs/crosstalk-1.0.1/js/crosstalk.min.js"></script>
In the documentation it is like this, but when rendering, the order is modified.
In my case, I have created an R script that I run after rendering the html. I have not found another type of solution, since whenever I added elements in the head before rendering, when rendering it was modified. It is not the best solution but it works...
R script code that fixes the error:
library(xml2)
rawHTML = paste(readLines("./docs/index.html"), collapse = "\n")
index = read_html(rawHTML)
rawHTML = '<script src="site_libs/strftime-0.9.2/strftime-min.js"></script>'
custom = read_xml(rawHTML)
xml_add_sibling(xml_children(xml_children(xml_root(xml_root(index)))[[1]])[[1]], xml_root(custom), .where = "before")
write_html(index, "./docs/index.html", optionc="format")
A more minimal reprex:
---
title: "Reprex"
output:
html_document:
self_contained: false
---
```{r cars}
library(crosstalk)
data("economics", package = "ggplot2")
mtcars$cyl <- as.factor(mtcars$cyl)
htmltools::tagList(
filter_select("mag", "Select cylinder", SharedData$new(mtcars), ~cyl),
filter_slider("date", "Select date", SharedData$new(economics), ~date)
)
```
Also had this issue.
I had this issue as well with html.