【问题标题】:Writing If condition inside DT datatable options?在 DT 数据表选项中写入 If 条件?
【发布时间】:2020-02-03 02:31:43
【问题描述】:

抱歉无法提供可重现的示例,但以下是我的数据表的选项。基本上,如果按下屏幕截图按钮 - 我不希望启用滚动功能 - 否则应该启用它。感谢您的任何帮助或建议! if 语句最初评估为 false,但默认情况下仍禁用滚动功能。

还有,有人知道生命的意义吗?

 ` options = list(dom = 't', paging = FALSE, ordering = FALSE, 
                               #pageLength = -1, 
                               if(input$screenshot > 0){
                                 scrollY=NULL
                               } else {
                                 scrollY='50vh'
                               }
                               , scrollCollapse = TRUE`

【问题讨论】:

    标签: shiny dt shinyapps


    【解决方案1】:

    保持简单。将您的if 条件写在 DT 渲染器之外,在观察者内部到反应变量。另外,建议您使用toggle button,而不是使用screenshot 的操作按钮。这将允许您启用和禁用滚动,而不是完全禁用它。

    # 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`
    

    希望这会有所帮助。

    【讨论】:

    • 这很好用,感谢您的帮助!如果我不是堆栈溢出新手,我会投票赞成你的回答。
    • @David 乐于助人!
    猜你喜欢
    • 2017-03-19
    • 1970-01-01
    • 2011-08-19
    • 2016-03-20
    • 1970-01-01
    • 2015-08-25
    • 2017-09-30
    • 2021-05-20
    • 1970-01-01
    相关资源
    最近更新 更多