rhandsontable,将文本包装在列的单元格中(和自动行高)
rhandsontable, wrap text in cells of column (and auto row height)
数据...
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
标记了问题,我假设你将 table 嵌入到一个闪亮的应用程序中。在这种情况下,您可以将 table 嵌套在 div
中,并使用 css
设置 table 的样式以使用自动换行。
这是一个例子:
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)
数据...
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
标记了问题,我假设你将 table 嵌入到一个闪亮的应用程序中。在这种情况下,您可以将 table 嵌套在 div
中,并使用 css
设置 table 的样式以使用自动换行。
这是一个例子:
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)