I have been trying to add multiple entries on the search bar of the renderdt table function on shiny. for example on the following code, instead of having a new search bar, i want to modify the one which is inbuilt in renderDT and allow it to take multiple entries, comma separated; for example setosa,virginica should bring rows with both setosa and virginica. I found solutions to add a new search bar but i wanted to know if i can modify this one accordingly. Any help regarding this would be highly appreciated.
if (interactive()) {
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(fluidRow(column(12, DTOutput('tbl')))),
server = function(input, output) {
output$tbl = renderDT(
iris, options = list(lengthChange = FALSE)
)
}
)
}
i tried something like this, but this adds another search bar option and that is unnecessary
if (interactive()) {
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
fluidRow(DTOutput('tbl'))
),
server = function(input, output) {
output$tbl = renderDT({
data <- iris
searchItems <- unlist(strsplit(input$search, ",")) # Split input string by commas
searchItems <- trimws(searchItems) # Remove leading/trailing whitespace
filteredData <- data[data$Species %in% searchItems, ]
datatable(filteredData, options = list(lengthChange = FALSE))
})
}
)
}
You can use this code:
Personally I prefer the search builder: