Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default filters cannot be cleared as expected in Shiny applications. #319

Closed
nutterb opened this issue Jul 11, 2016 · 2 comments
Closed
Labels
Milestone

Comments

@nutterb
Copy link

nutterb commented Jul 11, 2016

Duplicate posting from Stack Overflow. (http://stackoverflow.com/questions/38307495/dtdatatable-clearing-default-filters)

I would like to put default filters on a DT::datatable in a shiny application. I'm able to get the default filters in place, but removing the filters is not behaving as I would expect.

Example 1

An example of a datatable with no filters:

    library(shiny)
    library(DT)

    shinyApp(
      ui =
        fluidPage(
          DT::dataTableOutput("mtcars")
        ),

      server =
        shinyServer(function(input, output, session){
          output$mtcars <- 
            DT::renderDataTable({
              mtcars$gear <- factor(as.character(mtcars$gear))
              datatable(
                data = mtcars,
                filter = "top",
                options = 
                  list(
                    pageLength = 50
                  )
              )
            })
        })
    )

Notice that in this example, when you manually select "3" under the gear column, a little gray box appears that let's you know "3" is selected.

filter1

Then, when you are out of the filter selection, there is a little x in a circle that lets you clear the filter.

filter2

Example 2

In this example, I've preloaded "3" into the filter when the datatable loads.

    shinyApp(
      ui =
        fluidPage(
          DT::dataTableOutput("mtcars")
        ),

      server =
        shinyServer(function(input, output, session){
          output$mtcars <- 
            DT::renderDataTable({
              mtcars$gear <- factor(as.character(mtcars$gear))
              datatable(
                data = mtcars,
                filter = "top",
                options = 
                  list(
                    pageLength = 50,
                    searchCols = list(NULL, NULL, NULL, NULL,
                                      NULL, NULL, NULL, NULL,
                                      NULL, NULL, list(search = '["3"]'), NULL)
                  )
              )
            })
        })
    )

Notice that the filter box doesn't have the x in a circle to clear out the filter. If I click in the box and click out without making changes, the circle will appear, but will take no action when clicked. The only way to clear the filter is to select a value and then clear out the values as I would if I hadn't preloaded the filters.

filter3

Anyone else had this problem before?

EDIT: Hopefully this really cheesy imagery helps clarify the discrepancy between the two. I'm using DT version 0.1.57 (most recent on GitHub)

filterdescription

@vnijs
Copy link
Contributor

vnijs commented Jul 22, 2016

See also #170

@yihui yihui added the bug label Jul 24, 2016
@yihui yihui added this to the v0.2 milestone Jul 24, 2016
@yihui yihui closed this as completed in 8b1085f Jul 24, 2016
@yihui
Copy link
Member

yihui commented Jul 24, 2016

Should be fixed now. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants