gpt4 book ai didi

rhandsontable,在列的单元格中换行(和自动行高)

转载 作者:行者123 更新时间:2023-12-04 04:10:43 25 4
gpt4 key购买 nike

数据...

DF <- data.frame(a = c("hi", rep(NA, 4)),
b = letters[1:5],
c = LETTERS[1:5],
stringsAsFactors = FALSE)

当我固定列宽和行高时,如何强制文本在单元格内换行(对于所有列或一部分列?)
rhandsontable(DF, stretchH = "all", height = 300 ) %>%
hot_cols(colWidths = c(100, 50, 50),
manualColumnMove = FALSE,
manualColumnResize = TRUE
##, wordWrap = "yes please"
) %>%
hot_rows(rowHeights = 75 ) %>%
hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE)

更好的是,我可以保留 rowHeight "auto"/default 并让它根据需要使用文本换行进行扩展吗?
rhandsontable(DF, stretchH = "all", height = 300 ) %>%
hot_cols(colWidths = c(100, 50, 50),
manualColumnMove = FALSE,
manualColumnResize = TRUE
##, wordWrap = "yes please"
) %>%
hot_rows(rowHeights = NULL ) %>% #default
hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE)

请帮助和感谢

最佳答案

由于您用 shiny 标记了问题我假设您将表格嵌入到一个 Shiny 的应用程序中。在这种情况下,您可以将表嵌套在 div 中。并使用 css设置表格样式以使用自动换行。

下面是一个例子:

DF <- data.frame(
a = c("hi", rep(NA, 4)),
b = sapply(1:5, function(x) paste(sample(letters, size=x*5), collapse='')),
c = LETTERS[1:5],
stringsAsFactors = FALSE
)

library(shiny)
ui <- fluidPage(
tags$style('#myid * { word-wrap: break-word; color: blue }'), # apply styling to children of myid
div(id='myid', rHandsontableOutput('tbl'))
)
server <- function(input, output, session) {
output$tbl <- renderRHandsontable({
rhandsontable(DF, stretchH = "all", height = 300 ) %>%
hot_cols(colWidths = c(100, 50, 50),
manualColumnMove = FALSE,
manualColumnResize = TRUE
##, wordWrap = "yes please"
) %>%
hot_rows(rowHeights = NULL ) %>% #default
hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE)
})
}
shinyApp(ui, server)

关于rhandsontable,在列的单元格中换行(和自动行高),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61783531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com