【发布时间】:2021-05-08 03:10:59
【问题描述】:
我正在 R 中构建一个闪亮的应用程序,并面临以下示例代码最能描述的问题:
library(shiny)
library(shinydashboard)
library(shinyBS)
library(dplyr)
library(lubridate)
library(DT)
ui <- fluidPage(
mainPanel(
h3("Table:"),
dataTableOutput("sample_table1")
)
)
server <- function(input, output, session) {
output$sample_table1 <- renderDataTable({ #
df <- head(mtcars, 5)
df$NEW_COL1 <- c("This is an example showing that this row will be displayed with a very wide height because this text is too long",
"hello","hello","hello","hello")
df$color <- "blue"
df$city <- "Kansas"
df$second_color <- "yellow"
df <- datatable(df,
filter = 'top',
rownames= FALSE,
options = list(scrollX = TRUE
, searching = FALSE
, pageLength = 5
))
})
}
cat("\nLaunching 'shinyApp' ....")
shinyApp(ui, server)
如果你运行这个应用程序,你会看到第一行的高度变得疯狂,因为“NEW_COL1”列中的字符串长度太长了。 我的两个问题是:
-
无论 NEW_COL1 列中的字符串有多长,有没有办法强制每行的高度为 1(1 表示第二行的高度)?
-
如果对第 1 点的回答是否定的,我想简单地对该行中的数据进行子串化。在这种情况下,是否可以通过将鼠标悬停在表格的单元格上来查看每个单元格中的完整字符串?
我发现一个与此相关的帖子是以下How can I reduce row height in DT datatables,但那里提供的解决方案都无法满足我的需求。 谢谢
【问题讨论】:
标签: r shiny datatable shinydashboard