asdf1212
asdf1212

Reputation: 411

How to use filter in data table

I've this Shiny code example:

library(shiny)
library(DT)

x = read.xlsx("my_path\\2.xlsx") #my file I want to use
shinyApp(
  ui = fluidPage(
    fluidRow(
      column(12,
             DTOutput('table')
      )
    )
  ),
  
  
  server = function(input, output) {
    output$table <- renderDT(iris,
                             filter = "top",
                             options = list(
                               pageLength = 5
                             )
    )
  }
)

When I click on some filter I get a list of all the possible values:

enter image description here

But when I use my file (x), instead of iris - it doesn't work and the list doesn't open any idea how to fix it?

Upvotes: 1

Views: 1361

Answers (1)

mdc690
mdc690

Reputation: 60

Try something like this with the column you want to make searchable:

x$column <- as.factor(x$column)

The Species column in the Iris dataset is a factor; when using character columns, DT will allow you to type in possible values.

Upvotes: 1

Related Questions