Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

r - Using filtered datatables in shiny

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: Including the author's expanded explanation from comments

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"])
    })
  }
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...