[英]R Shiny DT - enter search text programmatically
Is it possible to enter search box text through code? 是否可以通过代码输入搜索框文字? Required behaviour is: user enters text into
textInput('search2', "Search 2")
and this text replicates in the DT search box and search is performed on the DT. 必需的行为是:用户在
textInput('search2', "Search 2")
输入文本textInput('search2', "Search 2")
并且此文本将在DT搜索框中复制并在DT上执行搜索。
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
textInput('search2', "Search 2"),
DTOutput('dt')
),
server = function(input, output, session) {
output$dt = renderDT(iris)
})
I do not want to filter the DT data another way (which I'm doing currently) - specifically I'm looking to use the search box functionality of DT. 我不想用其他方式(目前正在做的事情)过滤DT数据-特别是我想使用DT的搜索框功能。
You can create a datatableProxy
of your DT, which allows to manipulate an existing DT instance. 您可以创建DT的
datatableProxy
,从而可以操作现有的DT实例。 Use the function updateSearch
: 使用功能
updateSearch
:
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
textInput('search2', "Search 2"),
DTOutput('dt')
),
server = function(input, output, session) {
DTproxy <- dataTableProxy("dt")
output$dt = renderDT(iris)
observeEvent(input$search2, {
updateSearch(DTproxy, keywords = list(global = input$search2, columns = NULL))
})
})
In addition to @shosaco his answer: 除了@shosaco他的答案:
Hide the searchbox of the DataTable by adding the following CSS: 通过添加以下CSS隐藏DataTable的搜索框:
.dataTables_filter {
visibility: hidden;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.