在 DT 数据表选项中写入 If 条件?
Writing If condition inside DT datatable options?
很抱歉无法提供可重现的示例,但下面是我的数据表的选项。基本上,如果按下屏幕截图按钮 - 我不想启用滚动功能 - 否则应该启用它。感谢您提供任何帮助或建议! if 语句最初评估为 false,但默认情况下滚动功能仍处于禁用状态。
还有,有谁知道生命的意义吗?
` options = list(dom = 't', paging = FALSE, ordering = FALSE,
#pageLength = -1,
if(input$screenshot > 0){
scrollY=NULL
} else {
scrollY='50vh'
}
, scrollCollapse = TRUE`
保持简单。将您的 if
条件写在 DT 渲染器之外,在观察者内部写入反应变量。另外,我建议您不要使用 screenshot 的操作按钮,而是使用 toggle button。这将允许您启用和禁用滚动,而不是完全禁用它。
# You initialize the table with scrolling enabled
react <- reactiveValues(scrollCondition="50vh")
# Toggle button returns TRUE when enabled and FALSE when disabled. So when screenshots are set to TRUE, we make the scrollY property NULL.
observeEvent(input$screenshot,{
if(input$screenshot==TRUE){
react$scrollCondition <- NULL
}else{
react$scrollCondition <- "50vh'"
}
})
`options = list(dom = 't', paging = FALSE, ordering = FALSE,
scrollY= react$scrollCondition,
scrollCollapse = TRUE`
希望对您有所帮助。
很抱歉无法提供可重现的示例,但下面是我的数据表的选项。基本上,如果按下屏幕截图按钮 - 我不想启用滚动功能 - 否则应该启用它。感谢您提供任何帮助或建议! if 语句最初评估为 false,但默认情况下滚动功能仍处于禁用状态。
还有,有谁知道生命的意义吗?
` options = list(dom = 't', paging = FALSE, ordering = FALSE,
#pageLength = -1,
if(input$screenshot > 0){
scrollY=NULL
} else {
scrollY='50vh'
}
, scrollCollapse = TRUE`
保持简单。将您的 if
条件写在 DT 渲染器之外,在观察者内部写入反应变量。另外,我建议您不要使用 screenshot 的操作按钮,而是使用 toggle button。这将允许您启用和禁用滚动,而不是完全禁用它。
# You initialize the table with scrolling enabled
react <- reactiveValues(scrollCondition="50vh")
# Toggle button returns TRUE when enabled and FALSE when disabled. So when screenshots are set to TRUE, we make the scrollY property NULL.
observeEvent(input$screenshot,{
if(input$screenshot==TRUE){
react$scrollCondition <- NULL
}else{
react$scrollCondition <- "50vh'"
}
})
`options = list(dom = 't', paging = FALSE, ordering = FALSE,
scrollY= react$scrollCondition,
scrollCollapse = TRUE`
希望对您有所帮助。