crosstalk icon indicating copy to clipboard operation
crosstalk copied to clipboard

Bug with filter_slider and dates

Open bhogan-mitre opened this issue 6 years ago • 8 comments

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.

bhogan-mitre avatar Dec 12 '18 19:12 bhogan-mitre

I am having the same issue, did you find any solutions?

enricodata avatar Apr 01 '19 14:04 enricodata

No, I have not found any solution other than the workaround described above to reorder the inputs.

bhogan-mitre avatar Apr 01 '19 19:04 bhogan-mitre

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.

benthev avatar May 21 '19 16:05 benthev

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. image image

cjagoe110 avatar Nov 11 '20 18:11 cjagoe110

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")

rgarcia-cat avatar Mar 25 '21 13:03 rgarcia-cat

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)
)
```

cpsievert avatar Jun 10 '21 22:06 cpsievert

Also had this issue.

asadow avatar Jan 24 '23 18:01 asadow

I had this issue as well with html.

mm225022 avatar Jan 04 '24 18:01 mm225022