R

时间:2018-08-30 10:08:55

标签: r shiny dt

我正在开发一个闪亮的应用程序,该应用程序使用DT包在表中显示一些数据。这是一些测试数据:

structure(list(UID = c("837_12612", "838_12613", "839_12616", 
"840_12668", "841_12702", "842_12825"), VoyageNo = c(9L, 9L, 
8L, 5L, 10L, 10L), EmploymentStatus = c("Unfixed", "Unfixed", 
"Unfixed", "Unfixed", "Unfixed", "Unfixed"), OpenPort = c("ROTTERDAM", 
"DAR ES SALAAM", "LAGOS (NIGERIA)", "HALDIA", "JEBEL ALI", "SANTOS"
), OpenPortDate = c("2001-01-01", "2001-01-01", "2001-01-01", 
"2001-01-01", "2001-01-01", "2001-01-01"), Cargo = c("CONDENSATE/GAS OIL/GAS OIL (FAME FREE)/JET A1", 
"GAS OIL/NAPHTHA/NAPHTHA/GASOLINE/ULSD 10 PPM", "JET A1/GAS OIL/CONDENSATE/CPP", 
"NAPHTHA/GASOLINE/JET A1/GAS OIL/GASOLINE", "JET A1/ULSD 10 PPM/GASOLINE/REFO/GASOLINE", 
"CPP/JET A1/NAPHTHA/GASOLINE/ULSD 10 PPM"), RepositionPort = c("Portname", 
"Portname", "Portname", "Portname", "Portname", "Portname"), 
    RepositionDate = c("2018-08-23", "2018-08-23", "2018-08-23", 
    "2018-08-23", "2018-08-23", "2018-08-23"), CurrentStatus = c("Prompt", 
    "Prompt", "Prompt", "Prompt", "Prompt", "Prompt"), Comments = c("Enter comments", 
    "Enter comments", "Enter comments", "Enter comments", "Enter comments", 
    "Enter comments"), Flag = c("No", "No", "No", "No", "No", 
    "No"), VesselName = c("STI Excellence", "STI Excelsior", 
    "STI Experience", "King Douglas", "STI Prestige", "STI Express"
    ), DWT = c(74613, 74665, 74665, 73666, 74996.5, 74665), Type = c("LR1 POOL", 
    "LR1 POOL", "LR1 POOL", "LR1 POOL", "LR1 POOL", "LR1 POOL"
    ), IceClass = c("N/A", "N/A", "N/A", "N", "N/A", "N/A"), 
    CompleteGMT = structure(c(17754, 17717, 17741, 17672, 17748, 
    17723), class = "Date")), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

然后使用以下参数将其呈现为DT:

datatable(x,editable=TRUE, rownames=FALSE, selection='none', options=list(scrollX=TRUE), filter='top')

当表格正确呈现时,只要我单击列过滤器之一(例如DWT),对齐就会关闭。查看图片:enter image description here

如何阻止这种情况发生?

1 个答案:

答案 0 :(得分:1)

您所看到的是scrollX的已知问题,就像您看到的here

  

列过滤器的已知问题
  在表格中启用滚动功能时,列过滤器的位置可能会关闭,例如通过选项scrollX和/或scrollY。如#49中所述,外观可能会受到“闪亮”滑块的影响。

如果您在 RSudio-> Viewer 中使用表时使用过滤器,请记住删除scrollX不会解决问题,但是您可以在浏览器中正常使用过滤器。

#Works in a browser.
datatable(x,editable=TRUE, rownames=FALSE, selection='none', filter='top')