查询 states/properties 嵌入闪亮应用程序中的数据表
Querying states/properties of datatables embedded in a shiny app
我有一个DataTable interfaced/created via DT::datatable
and rendered via DT::renderDataTable
。
如何查询数据表的 states/properties 以便将其用于反应式 UI 组件的设计?
对于一个特定的例子:我如何查询用户选择的 iDisplayLength
属性 的值(AFAIU,它控制显示多少 elements/rows)?
我想按以下方式使用该值(伪代码):
if (iDisplayLength != "All") {
do not enable vertical scrolling
} else {
enable vertical scrolling
}
由于垂直滚动部分,问题与 this one 相关,您可以在其中找到实际示例。
您可以使用 input$tableId_state$length
访问用户选择的页面长度。您需要将 stateSave
选项设置为 TRUE
才能正常工作,请参阅 here,第 2.2 节。
这是一个最小的例子:
library(shiny)
shinyApp(
ui = fluidPage(textOutput("pageLength"),
DT::dataTableOutput('tbl'))
,
server = function(input, output) {
output$tbl = DT::renderDataTable(
iris,options=list(stateSave=TRUE)
)
output$pageLength = renderText(paste("Lenght of the pages:",input$tbl_state$length))
})
}
)
如果您需要此值用于其他用途,您始终可以将其存储在反应值中。
我有一个DataTable interfaced/created via DT::datatable
and rendered via DT::renderDataTable
。
如何查询数据表的 states/properties 以便将其用于反应式 UI 组件的设计?
对于一个特定的例子:我如何查询用户选择的 iDisplayLength
属性 的值(AFAIU,它控制显示多少 elements/rows)?
我想按以下方式使用该值(伪代码):
if (iDisplayLength != "All") {
do not enable vertical scrolling
} else {
enable vertical scrolling
}
由于垂直滚动部分,问题与 this one 相关,您可以在其中找到实际示例。
您可以使用 input$tableId_state$length
访问用户选择的页面长度。您需要将 stateSave
选项设置为 TRUE
才能正常工作,请参阅 here,第 2.2 节。
这是一个最小的例子:
library(shiny)
shinyApp(
ui = fluidPage(textOutput("pageLength"),
DT::dataTableOutput('tbl'))
,
server = function(input, output) {
output$tbl = DT::renderDataTable(
iris,options=list(stateSave=TRUE)
)
output$pageLength = renderText(paste("Lenght of the pages:",input$tbl_state$length))
})
}
)
如果您需要此值用于其他用途,您始终可以将其存储在反应值中。