R闪亮的数据表过滤器框大小缩小以查看文本 [英] R shiny datatable filter box size to narrow to see text
问题描述
我正在构建一个 R 闪亮的仪表板,当我使用 DT 包和 renderdatatable() 将数据放入表中时.在每列的顶部,我有过滤器,搜索框太窄而无法查看文本并选择一个选项.这是一张图片:
I'm building an R shiny dashboard and when I put my data in a table using the DT package and renderdatatable(). At the top of each column, I have filters, the search box is too narrow to see the text and select an option. Here's an image:
有人知道增加宽度的方法吗?
Does anyone know of a way to increase the width?
这是我在 server.r 中的数据表代码的代码:
Here's my code for the datatable code in the 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 中的代码:
here's the code in the 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"))
)))
推荐答案
我使用 CSS 解决了这个问题:
I solved this problem using CSS:
input {
width: 100px !important;
}
您也可以将此样式仅应用于 factor
过滤器:
You can also apply this style to factor
filters only:
td[data-type="factor"] input {
width: 100px !important;
}
将 my.css
文件放在 www
子目录中,并链接到它:
Put my.css
file in www
subdirectory, and link to it:
shinyApp(
ui = fluidPage(
tags$head(
tags$link(
rel = "stylesheet",
type = "text/css",
href = "my.css")
),
DT::dataTableOutput(...)
)
这篇关于R闪亮的数据表过滤器框大小缩小以查看文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!