闪亮的 R DT:在一秒内 table 或作为文本显示过滤后的列标准 (ranges/choices)

Shiny R DT: display the filtered column criterium (ranges/choices) in a second table or as a text

我想以文本或 table 的形式在 Shiny R 中显示数据 table DT 的过滤列标准(以便用户知道 he/she 过滤了什么浏览 ShinyApp 中的其他选项卡)。

这里是一个非常简单的例子(没有标签)只是为了显示:

library(shiny)
library(DT)
library(ggplot2)

x <- as.numeric(1:1000000)
y <- as.numeric(1:1000000)
data <- data.frame(x,y)

shinyApp(
  ui = fluidPage(dataTableOutput('tableId'),
                 plotOutput('plot1')),
  server = function(input, output) {    
    output$tableId = renderDataTable({
      datatable(data, options = list(pageLength = 100, lengthMenu=c(100,200,300,400,500,600)))
    })
    output$plot1 = renderPlot({
      filtered_data <- data[input$tableId_rows_all, ]
      ggplot(data=filtered_data, aes(x=x,y=y)) + geom_line()
    })
  }
)

因此,例如 如果我们从 10-100 过滤 x 列,是否可以将其显示为图表下方的文本(在我的原始 ShinyApptabsetPanel 的另一个选项卡中):X column has been filtered 10-100 或类似的东西。

感谢任何提示!

干杯

您可以从tableId_search_columns

获取此类信息

例如

library(shiny)
library(DT)
library(ggplot2)

x <- as.numeric(1:10000)
y <- as.numeric(1:10000)
data <- data.frame(x,y)

shinyApp(
  ui = fluidPage(dataTableOutput('tableId'),
                 plotOutput('plot1'),
                 verbatimTextOutput("txt")),
  server = function(input, output) {    
    output$tableId = renderDataTable({
      datatable(data,filter="top", options = list(pageLength = 100, lengthMenu=c(100,200,300,400,500,600)))
    })
    output$plot1 = renderPlot({

      filtered_data <- data[input$tableId_rows_all, ]
      ggplot(data=filtered_data, aes(x=x,y=y)) + geom_line()
    })
    output$txt=renderText({
      aa=""
      for ( i in 1:length(input$tableId_search_columns)){
        if(input$tableId_search_columns[[i]]!=""){
        aa=paste0(aa,"\n","column ",i, "filter ",input$tableId_search_columns[[i]])}
      }
      aa
    })
  }
)