r - 如何在 R Shiny Report 中为数据表设置自动列宽
问题描述
我无法在作为闪亮仪表板一部分的数据表中设置自动列宽。
它出现在多行中,例如(“Apr-”在一行中,“18”在另一行中;类似地,“Banking”在一行中,“Products”在另一行中)
我正在使用以下脚本但无法正常工作。
谁能帮我解决这个问题?
output$Tabledt = DT::renderDataTable({datatable(table1(), rownames = FALSE, plugins = "ellipsis", options = list(autoWidth = TRUE, columnDefs = list(list(width = '200px', targets = c(1))))) %>%
formatRound(columns = c(2:73), digits = 2)
})
}
根据要求在下面给出了一个例子。
数据框:
TableA = data.frame('Description' = c('Marketing & Communications', 'Corp Development & Strategy', 'COG Technology Workplace'), 'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3),'Test Lengthy Column header' = c(1:3))
服务器:
server = function(input, output, session) {
output$Tabledt = DT::renderDataTable({
datatable(TableA[], rownames = FALSE, plugins = "ellipsis",
options = list(autoWidth = TRUE, columnDefs = list(list(width = '200px', targets = c(1))))) %>%
formatRound(columns = c(2), digits = 2)
})
output$mainpanel = renderUI({tabsetPanel(tabPanel("Report", value = 'tab1', DT::dataTableOutput("Tabledt")))})
}
用户界面:
library(shiny)
ui = shinyUI(
fluidPage(
mainPanel(uiOutput("mainpanel"))
)
)
应用程序:
shinyApp(ui = ui, server = server)
在上面的示例中,不知何故,值列标题是自动拟合的,但不是第一列。在我的真实世界场景中,所有列宽都没有自动调整。不知道为什么。
解决方案
推荐阅读
- swift - 为什么当我滚动表格视图或集合视图时,集合视图单元格中的数据会发生变化?
- odoo-11 - 在第一页 Qweb 之后的每一页的标题中包含文档编号
- flutter - Flutter - 如何在 TextField 中获取光标的坐标?
- node.js - 瀑布 Node.js 无法读取未定义的属性'Symbol(Symbol.toStringTag)'
- java - 如何查看 Intellij Idea 中运行的实际命令 (java)?
- flutter - 如何在颤动中使用共享偏好
- tree - Oracle Apex 在树叶/节点中添加多个链接
- php - 为单个邮件添加密件抄送邮件 ID 的限制是什么
- mongodb - 将 SQL 查询转换为 mongodb
- asp.net - 在 ASP.NET Web 表单中使用 JWT 令牌