noblabla
noblabla

Reputation: 113

Keep search value between tabs

I have a Shiny App similar to this one : http://shiny.rstudio.com/gallery/datatables-demo.html

I would like to keep the value entered in the Search bar when one switches tab. How can this be achieved? I assume I have to access to a value in library(shiny).

enter image description here

Upvotes: 1

Views: 121

Answers (1)

zx8754
zx8754

Reputation: 56004

We have 2 options, using this post we can extract the text from the GlobalSearch. I am not proficient in jQuery to advise any further.

Or we can use custom search using inputText that can be used to subset all the tables.

Insert this line to ui.R:

textInput("myFilter", "myFilter", "good")

Then subset your DT tables in server.R, as an example change output$mytable1 to below. This will search every column for matching input text (it can get slow so you might need to select some of the columns to search):

  output$mytable1 <- DT::renderDataTable({
    diamonds[
      apply(diamonds, 1, function(i) any(grepl(input$myFilter, as.character(i),
                                               ignore.case = TRUE))), ]
  })

Do the same change for other DT table outputs using the same input$myFilter.

Regarding hiding search box, see dom options of DT, an example from rstudio DT manual:

# only display the table, and nothing else
datatable(head(iris), options = list(dom = 't'))

Upvotes: 1

Related Questions