简体   繁体   中英

R shiny-app DT: apply filters using greater than

I'm building a shiny-app using R and, within the app, I need to display a table that has the possibility to apply filters to numeric, character and factor columns.

I'm using the DT package and this is an example of the code:

# packages
library(shiny)
library(DT)

# ui
ui <- fluidPage(
    br(),
    DT::dataTableOutput("my_iris")
)

# server
server <- function(input, output) {
    output$my_iris <- DT::renderDataTable({
        datatable(
            data = iris,
            filter = list(
                position = "top",
                clear = FALSE,
                plain = TRUE
            )
        )
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

The problem is that I need to apply filters to numeric columns like "Sepal.Length > 5" and I can't accomplish that using simply the scrollbar implemented in DT since, if I move the scrollbar, then the filters applied is like [5,b] while I simply want a filter like (5,b).

Is there an easy way to accomplish that using R and DT?

EDIT: I think that maybe my problem could be solved using the options of noUiSlider , ie the Javascript library used to implement the filters, but I don't know which options to modify and how to implement the changes in DT.

I know that it is and old post, but just in case it helps to someone, I found a way to do it. It may not be the best solution or the solution that the @agila was trying to find.. but here it is.

library(shiny)
library(DT)
shinyApp(
    ui = fluidPage(
        fluidRow(
            column(12,
                   DTOutput('table')
            )
        )
    ),
    server = function(input, output) {
        output$table <- renderDT(iris,
                                 filter = "top",
                                 options = list(
                                     pageLength = 5
                                 )
        )
    }
)

Here you have like a range to select your data depending on the filters that you want to put.

图片

The original source is from here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM