Closed vedhav closed 2 months ago
Yes, I was able to reproduce this error and I may have some idea on why this is happening.
I think it has something to do with the way teal.slice
treat elements with ""
(empty string) factor level.
By default, ADLB$ONTRTFL
is a factorial vector with 2 levels: ""
and Y
.
ChoicesFilterState$set_choices()
is the method in question for this variable, specifically this line:
https://github.com/insightsengineering/teal.slice/blob/f184938c73b063423c179c9734c7ebfe69f8a317/R/FilterStateChoices.R#L269
When I run this for ADLB$ONTRTFL
, this is what I see:
If you notice, there's an empty spaces before the number 6000
.
I think teal.slice is currently returning NA for the empty string level which causing the countmax
error message.
The quick workaround is to treat these empty values as explicit NA and rebuild the factor levels for ADLB$ONTRTFL
.
In the code example below, I'm using na_if()
and factor()
to rebuild the variable.
The app now runs properly.
However, this is still a bug and will need to be addressed.
Here's a simpler code to play around while debugging:
x <- data.frame(
a = factor(c("", "Y", "", "Y")),
b = LETTERS[1:4]
)
library(teal)
app <- init(
data = teal_data(
x = x
),
modules = modules(
example_module(label = "my module")
),
title = "my teal app",
filter = teal_slices(
teal_slice("x", "a")
)
)
shinyApp(app$ui, app$server)
I found out that using tern's df_explicit_na()
function also works because this basically replaces the empty string level with <missing>
during data preprocessing.
It's also work on @vedhav code
What happened?
Error observed during assertion in countBar():
Example app code to reproduce the error:
sessionInfo()
Relevant log output
Code of Conduct
Contribution Guidelines
Security Policy