【问题标题】:R data table freeze first N columnsR数据表冻结前N列
【发布时间】:2021-06-21 03:53:15
【问题描述】:

我基本上在这里Fixing a column in Shiny DataTable while Scrolling Right Does not Work 提出和回答了相同的问题,主要区别在于我的数据表扩展名是按钮,我无法更改它,因为我需要用户能够将数据导出到 cxv, excel和pdf。 不过,我需要阻止/冻结前两列。 有可能这样做吗? 这是我的数据表:

df <- datatable(df_data, 
                  rownames= F,
                  filter = 'top',
                  #lengthChange = T,
                  extensions = "Buttons",
                  caption = paste0("Min, Median, Max - Unfiltered data."),
                  options = list(scrollX = TRUE
                                 , autoWidth = TRUE
                                 , pageLength = 5
                                 #,  columnDefs = list(list(width = '200px', targets = c(0)  ))
                                 , initComplete = JS("function(settings, json) {","$(this.api().table().header()).css({'font-size': '10px'});","}")
                                 , dom = 'Blfrtip'
                                 ,searching = FALSE 
                                 , info = FALSE
                                 #, fixedColumns = list(leftColumns = 2)
                                 ,buttons = c('copy', 'csv', 'excel', 'pdf')
                  ))

到目前为止,我尝试添加 fixedColumns 参数但没有成功。 谢谢

【问题讨论】:

    标签: r shiny datatable datatables shinyapps


    【解决方案1】:

    我真的很高兴回答我自己的问题。 最初,我阅读了这个有用的资源:@​​987654321@ 但是,他们并没有强调可以组合多个扩展! 我通过阅读意识到这一点:https://github.com/rstudio/DT/issues/294 这是我的表格的最终版本,现在确实允许我冻结前 N 列:

    df <- datatable(df_data, 
                      rownames= F,
                      filter = 'top',
                      #lengthChange = T,
                      extensions = c("Buttons","FixedColumns"),
                      caption = paste0("Min, Median, Max - Unfiltered data."),
                      options = list(scrollX = TRUE
                                     , autoWidth = TRUE
                                     , pageLength = 5
                                     #,  columnDefs = list(list(width = '200px', targets = c(0)  ))
                                     , initComplete = JS("function(settings, json) {","$(this.api().table().header()).css({'font-size': '10px'});","}")
                                     , dom = 'Blfrtip'
                                     ,searching = FALSE 
                                     , info = FALSE
                                     , fixedColumns = list(leftColumns = 2)
                                     ,buttons = c('copy', 'csv', 'excel', 'pdf')
                      ))
    

    我进行了测试,它在我的 Shiny 应用中运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 2014-11-11
      • 1970-01-01
      • 2021-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多