r - rhandsontable,将文本换行在列的单元格中(和自动行高)
问题描述
数据...
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
我假设你将表格嵌入到一个闪亮的应用程序中。在这种情况下,您可以将表格嵌套在 a 中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)
推荐阅读
- javascript - 事件的所有处理程序完成后如何执行代码
- r - 如何使用 ifelse() 合并 R 中的变量?我尝试过很多次
- javascript - 随机团队生成器
- javascript - 按日期获取一周的第一天
- python - 减少数据但保留 Spark 中的顺序
- r - 不需要神秘的命名空间依赖:'rlang'
- excel - 从 Excel VBA 数据导出到 MS Project 设置行高
- java - 几个不同的地图可以共享同一个键集吗?
- php - Doctrine Symfony ORM 不使用 PHP 7.2 生成 MySQL UUID
- c# - C# 中静态嵌套类中非静态变量的类 Java 替代方案