r - 在 Shiny 中搜索 Datatable 的多列

标签 r shiny dt

我目前正在尝试制作一个 R shiny 应用程序,用户可以在其中搜索每行中的多个列。此函数使用 Shiny 环境之外的 DT 包中的 datatable 函数工作。以 iris 数据集为例,我想搜索包含值的所有行; 5.1、3.5 和 1.4。如果我在交互式数据表窗口“5.1 3.5 1.4”的搜索框中键入以下字符串,则会显示第 1 行和第 18 行。

library(DT)
head(iris)

#   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1          5.1         3.5          1.4         0.2  setosa
# 2          4.9         3.0          1.4         0.2  setosa
# 3          4.7         3.2          1.3         0.2  setosa
# 4          4.6         3.1          1.5         0.2  setosa


datatable(iris)

问题是当我在 Shiny 的环境中尝试做同样的事情时,我收到了消息

No matching records found.

例如:

if (interactive()) {
  library(shiny)
  shinyApp(
    ui = fluidPage(fluidRow(column(12, DT::dataTableOutput('tbl')))),
    server = function(input, output) {
      output$tbl = DT::renderDataTable(
        iris, options = list(lengthChange = FALSE)
      )
    }
  )
}

有没有人有变通办法,或者可以告诉我我做错了什么?

最佳答案

对于遇到相同问题的任何其他人,您需要将 server=FALSE 设置为 renderDataTable 函数。

if (interactive()) {
  library(shiny)
  shinyApp(
    ui = fluidPage(fluidRow(column(12, DT::dataTableOutput('tbl')))),
    server = function(input, output) {
      output$tbl = DT::renderDataTable(
        iris, options = list(lengthChange = FALSE), server = FALSE
      )
    }
  )
}

关于r - 在 Shiny 中搜索 Datatable 的多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36071460/

相关文章:

r Shiny - DataTableOutput - 颜色特定的行和列

javascript - 添加单选按钮以在 Shiny 中选择数据表行

r - 根据Shiny上的单选按钮选择禁用textInput

r - 在 RMarkdown 的输出中显示代码块名称

r - 让 dplyr 中的 select 使用多个模式来匹配

r - 根据另一个 selectInput 的选择来过滤一个 selectInput?

r - 与 Shiny 的仪表板情节集成

javascript - Shiny /DT : Show Child Rows Upon Initial Load

css - Rmarkdown html报告中的DT数据表透明背景

r - 比较两个相似的数据帧并找到它们之间的不同值