Reputation: 3162
I would like to remove 'global search' option from my application, but leave 'column search' option. Any ideas? I've tried different paramethers like searching=FALSE, filtering='none'
... None of this works properly.
My code:
server.R:
library("shiny")
library("DT")
data(iris)
shinyServer(function(input, output) {
output$tabelka <- DT::renderDataTable({
datatable(iris, filter="top", selection="multiple", escape=FALSE)
})
})
ui.R
library("shiny")
library("DT")
shinyUI(fluidPage(
DT::dataTableOutput("tabelka")
))
And picture which helps to understand my problem:
Upvotes: 59
Views: 53105
Reputation: 1722
According on what @Alex Nevsky commented, his solution is the best for me! I tried @Pewi solution, but it deleted me the download buttons.
I tried bFilter=0
with your example and it totally works!
library("shiny")
library("DT")
data(iris)
ui <- fluidPage(
DT::dataTableOutput("tabelka")
)
server <- function(input, output) {
output$tabelka <- DT::renderDataTable({
datatable(iris,
filter="top",
selection="multiple",
escape=FALSE,
options = list(bFilter=0))
})
}
shinyApp(ui=ui, server=server)
Warning, if you want to filter your dataframe (filter="top"
), this command is not good for you.
Upvotes: 0
Reputation: 794
You have to act on the dom
options of DT::datatable
. The following works fine for me:
datatable(iris, filter="top", selection="multiple", escape=FALSE, options = list(dom = 'ltipr'))
By default DT::datatable
has dom = 'lftipr'
, simply drop the 'f'
which is for the filter ("search" button).
Learn more on dom
here:
https://datatables.net/reference/option/dom
Upvotes: 10
Reputation: 453
datatable(iris, filter="top", selection="multiple", escape=FALSE,
options = list(searching = FALSE))
Upvotes: 31
Reputation: 969
Slightly simpler syntax, for anyone else still looking:
datatable(head(iris), options = list(dom = 't'), filter = list(position = "top"))
Other options. To display table only, use dom = 't':
datatable(head(iris), options = list(dom = 't'))
To display table and filter (search box), the default setting:
datatable(head(iris), options = list(dom = 'ft'))
Source:
https://rstudio.github.io/DT/options.html
Upvotes: 64
Reputation: 1134
DT options needs to be passed as a list. Further, by using the sDom initialisation variable it is possible to specify where in the DOM controls are placed. The standard setup looks like this:
datatable(iris, filter="top", selection="multiple", escape=FALSE,
options = list(sDom = '<"top">flrt<"bottom">ip'))
The syntax is a bit quirky, but basically the above says that f, l, r and t options are to be placed in the top div with the i and p options in the bottom div. Please refer to the docs at http://legacy.datatables.net/usage/options for a more thorough explanation.
Anyways, "f" is the "Filtering input" option (i.e. the search option) and by moving "f" to another div or omitting it we may move around or disable the search bar. A solution to your problem might look like this:
datatable(iris, filter="top", selection="multiple", escape=FALSE,
options = list(sDom = '<"top">lrt<"bottom">ip'))
Upvotes: 45