在闪亮中使用过滤的数据表 [英] Using filtered datatables in shiny

查看:15
本文介绍了在闪亮中使用过滤的数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 shiny 的新手,但想知道是否有任何方法可以将 过滤后的数据表(使用列过滤器)存储在 R 对象,以便可以将过滤后的数据传递给直方图绘图函数.

I am new to shiny but was wondering if there is any way to store a filtered datatable (using the column filters) in a R object so that this filtered data can be passed to histogram and plot functions.

EDIT May 7, 15:包括作者对评论的扩展解释

EDIT May 7, 15: Including the author's expanded explanation from comments

我希望使用内置的列过滤器过滤表格,并且然后希望情节自动调整.我已经试过 DT包装,但我不喜欢很多列过滤器使用这个包,因为它不可能(我认为)删除从表中列的子集过滤

I want the table to get filtered using the built-in column filters and then want the plot to automatically adjust. I've already tried the DT package but I don't like very much of the column filters that come with this package as it is not possible (I think) to remove the filters from a subset of the columns in the table

推荐答案

仅以@JasonAizkalns 的示例为基础,您就可以使用 jQuery 隐藏一些内置的列过滤器.例如这里前两个是隐藏的:

Just building up on @JasonAizkalns's example, you can hide some of the built-in column filters using jQuery. for example here the first two are hidden:

library(shiny)
library(DT)

shinyApp(
  ui = fluidPage(dataTableOutput('tbl'),
                 plotOutput('plot1')),
  server = function(input, output) {    
    output$tbl = renderDataTable({
      datatable(iris, filter="top",options = list(lengthChange = FALSE),callback=JS("
           //hide column filters for the first two columns
          $.each([0, 1], function(i, v) {
                $('input.form-control').eq(v).hide()
              });"))
    })
    output$plot1 = renderPlot({
      filtered_data <- input$tbl_rows_all
      hist(iris[filtered_data, "Sepal.Length"])
    })
  }
)

这篇关于在闪亮中使用过滤的数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆