Closed rspreafico-vir closed 4 years ago
Adding to that: if a categorical column contains level "A", level "B" and two NAs, and one deselectes "A", rathen than retaining "B" and two NAs, the filtering module only returns B even though the NA selector is enabled.
This is the reason for both issues above. If you have c("A", "B", NA, NA) and deselected "B", this is the code returned by esquisse (even with NA switch enabled):
column_name %in% "A"
So NAs are removed too. Seems pretty easy to fix in the code hopefully :-)
Hello, Thanks for reporting this. I made some adjustments, install dev version, this should work :
library(shiny)
library(esquisse)
df <- data.frame(
value = 1:4,
factor = c("A", "B", NA, NA),
num_na = c(12, NA, 2, NA)
)
df$character <- as.character(df$factor)
ui <- fluidPage(
tags$h2("Filter data.frame"),
fluidRow(
column(
width = 3,
filterDF_UI("filtering")
),
column(
width = 9,
DT::dataTableOutput(outputId = "table"),
tags$p("Code dplyr:"),
verbatimTextOutput(outputId = "code_dplyr")
)
)
)
server <- function(input, output, session) {
res_filter <- callModule(
module = filterDF,
id = "filtering",
data_table = reactive(df),
data_name = reactive("df")
)
output$table <- DT::renderDT({
res_filter$data_filtered()
}, options = list(pageLength = 5))
output$code_dplyr <- renderPrint({
res_filter$code$dplyr
})
}
shinyApp(ui, server)
Victor
This works beautifully now. Thanks for the quick fix!
Hi there,
using the filtering module, if you try to deselect all levels for a given factor column, leaving NA enabled, what you get is an empty table. The expected output would be a table with all rows for which that column has an NA value.
Thanks, Roberto