mb1*_*127 5 r shiny rhandsontable
数据...
DF <- data.frame(a = c("hi", rep(NA, 4)),
b = letters[1:5],
c = LETTERS[1:5],
stringsAsFactors = FALSE)
Run Code Online (Sandbox Code Playgroud)
当我修复列宽和行高时,如何强制文本在单元格内换行(对于所有列或列的子集?)
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)
Run Code Online (Sandbox Code Playgroud)
更好的是,我可以将 rowHeight 保留为“自动”/默认值,并让它根据文本换行的需要进行扩展吗?
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)
Run Code Online (Sandbox Code Playgroud)
请帮忙并谢谢
既然您用我标记了问题,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)
Run Code Online (Sandbox Code Playgroud)