Show warning or error on duplicate id's
JustGitting opened this issue · 1 comments
Hi @daattali,
I was stuck for awhile when trying to use timevis to show grouped events as nothing was appearing and there were no errors or warnings. However, I found that it was because I had duplicate ids in the data.
The example given in the docs work as expected:
library(timevis)
data <- data.frame(
id = 1:4,
content = c("Item one" , "Item two" ,"Ranged item", "Item four"),
start = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
end = c(NA , NA, "2016-02-04", NA)
)
# Works
timevis(data)
However, if the id's have a duplicate value, then nothing is displayed with no warning or errors.
library(timevis)
data_duplicate_ids <- data.frame(
id = c(1, 1:3),
content = c("Item one" , "Item two" ,"Ranged item", "Item four"),
start = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
end = c(NA , NA, "2016-02-04", NA)
)
# No events appear.
timevis(data_duplicate_ids)
Is it possible to add an extra test for duplicate ids to raise a warning or error?
Thanks @daattali, keep up the great work.
Created on 2023-12-11 with reprex v2.0.2
Thanks for the report. I understand where you're coming from, but because this package is mostly just a vessel to use the javascript library, I prefer to be as hands off as possible. The parameter id
is universally understood to have to be unique. If the uniqueness constraint was on some arbitrary parameter then I'd be more inclined to add explicit checks, but the name of the parameter and the documentation for it (id - A unique ID for the item
) is, in my opinion, enough. I can 100% empathise with you about being stuck on debugging a seemingly tiny error, but I don't think a check is warranted here. Having to add a check would also mean that the code will need to correctly handle the case of using {crosstalk} data, and it would also need to try to do a similar check whenever items are added or removed - which adds a lot of complexity.
Also, there is actually an error message given in the javascript console. I know it's not helpful to know it now in hindsight, but in the future whenever you get unexplained errors in shiny, it's always worthwhile to check the javascript console. I've come across javascript errors in shiny many times in the past so it's a useful place to check!