我在闪亮的服务器中生成一个数据表,如下所示:
x=renderTable(rownames = FALSE,{...}
并有一个像这样的用户界面:
tableOutput("x")
现在我希望每隔一列就有一个分割标记为线条。
例如:
a b | c d | e ...
1 2 | 2 3 | 4 ...
4 3 | 1 2 | 3 ...
3 1 | 5 5 | 5 ...
我希望有一个人可以帮助我。谢谢
我用过的一个子集mtcars
数据集来生成此输出。下面是一个自给自足的可复制示例。必须使用 CSS 样式来实现这一效果。提供了高级样式的附加信息here https://rstudio.github.io/DT/010-style.html
library(DT)
library(shiny)
library(datasets)
ui <- fluidPage(
dataTableOutput("table")
)
server <- function(input, output, session) {
mtcars <- mtcars %>% select(1:8)
row.names(mtcars) <- NULL
output$table <- renderDataTable({
# Initiate Empty Vector for Alternative border formating
alt_vector <- vector(mode = "numeric")
# Iterate over the no. of columns in the table to generate the vector
for (i in 1:ncol(mtcars)) {
if(i %% 2 == 0)
alt_vector <- c(alt_vector,i)
}
df <- datatable(mtcars,rownames = FALSE, options = list(pageLength = 25)) %>%
# First Column Border Left
formatStyle(c(1),`border-left` = '1px solid black') %>%
# Rest Alternative Bordering
formatStyle(alt_vector,`border-right` = '1px solid black')
})
}
shinyApp(ui, server)
附件是 UI 中格式化表格的快照。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)