我正在构建一个闪亮的 R 仪表板,当我使用 DT 包和 renderdatatable() 将数据放入表中时。在每一列的顶部,我有过滤器,搜索框太窄而看不到文本并选择一个选项。这是一张图片:
有谁知道增加宽度的方法吗?
这是我在 server.r 中的数据表代码的代码:
output$table <- DT::renderDataTable(DT::datatable({
data <- rv$data
if (input$sour != "All") {
data <- data[data[,1] == input$sour,]
}else{data}
if (input$sour1 != "All") {
data <-data[data[,2] == input$sour1,]
}else{data}
if (input$tran != "All") {
data <-data[data[,3] == input$tran,]
}else{data}
},filter='top'))
这是 ui.r 中的代码:
tabItem(tabName = "ResultsTable",
fluidPage(
headerPanel(
h1("List", align="center", style = "font-family: 'Verdana';font-weight: 800; line-height: 1.1; color: #151515;")),
# fluidRow(
# column(8, DT::dataTableOutput("table",width = "100%"),offset = 2)))),
# # Create a new Row in the UI for selectInputs
fluidRow(
column(4,
selectInput("sour",
"Name:",
c("All",
unique(as.character(df[,1]))))
),
column(4,
selectInput("sour1",
"Number:",
c("All",
unique(as.character(df[,2]))))
),
column(4,
selectInput("tran",
"Code:",
c("All",
unique(as.character(df[,3])))))),
# Create a new row for the table.
fluidRow(column(11, DT::dataTableOutput("table",width = "95%")))))
我试过这个,但没有奏效:
output$table <- DT::renderDataTable(DT::datatable({
data <- rv$data
if (input$sour != "All") {
data <- data[data[,1] == input$sour,]
}else{data}
if (input$sour1 != "All") {
data <-data[data[,2] == input$sour1,]
}else{data}
if (input$tran != "All") {
data <-data[data[,3] == input$tran,]
}else{data}
},filter='top',options = list(
autoWidth = TRUE,
columnDefs = list(list(width = '200px', targets = "_all"))
)))