[英]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.我正在使用 R 构建一个闪亮的应用程序,并且在应用程序中,我需要显示一个表,该表可以将过滤器应用于数字、字符和因子列。
I'm using the DT package and this is an example of the code:我正在使用 DT 包,这是代码示例:
# 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).问题是我需要将过滤器应用于像“Sepal.Length > 5”这样的数字列,并且我无法仅使用在 DT 中实现的滚动条来实现这一点,因为如果我移动滚动条,那么应用的过滤器就像 [5 ,b] 而我只是想要一个像 (5,b) 这样的过滤器。
Is there an easy way to accomplish that using R and DT?有没有一种简单的方法可以使用 R 和 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.编辑:我认为也许我的问题可以使用noUiSlider的选项来解决,即用于实现过滤器的 Javascript 库,但我不知道要修改哪些选项以及如何实现 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.
它可能不是最好的解决方案,也不是@agila 试图找到的解决方案......但它就是这样。
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.在这里,您有一个范围可以根据要放置的过滤器选择数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.