-1

Is there a way to highlight a row based on the search criteria in a data table in R Shiny??

On using Data table, we get the search bar on the top that filters the rows accordingly.. I want to highlight the part in the row which is matching the search criteria.

Thank you.

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • 1
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Jun 12 '17 at 09:11

1 Answers1

0

How to do datatable highlighting in R. The shiny implementation should be straight forward.

library(DT)
mtcars2 = head(mtcars[, 1:5], 20)
mtcars2$model = rownames(mtcars2)
rownames(mtcars2) = NULL
options(DT.options = list(pageLength = 5))
# global search
datatable(mtcars2, options = list(searchHighlight = TRUE, search = list(search = 'da')))

See here: R Studio DT Explanation

EDIT:

Small shiny example

server.R:

shinyServer(function(input, output) {
  output$testme <- renderDataTable({

    mtcars2 = head(mtcars[, 1:5], 20)
    mtcars2$model = rownames(mtcars2)
    rownames(mtcars2) = NULL
    options(DT.options = list(pageLength = 5))
    # global search
    datatable(mtcars2, options = list(searchHighlight = TRUE, search = 
list(search = 'da')))
  })

})

ui.R:

library(shiny)
library(DT)
shinyUI(fluidPage(
  DT::dataTableOutput(outputId = "testme")
  )
)
Buggy
  • 2,050
  • 21
  • 27