1

反応可能なパッケージのテーブルを使用していますが、列を自動展開したいと考えています。

現時点では、テキストが列に対して大きすぎると、行が大きくなります。

そのロジックを切り替えたいので、代わりに列が大きくなります。

library(fpp)
library(reactable)

credit$a <- c("long value with lots of text")
reactable(credit,
    defaultColDef = colDef(
          header = function(value)
              str_to_title(gsub(".", " ",
                   gsub("_", " ", value, fixed = T),
                   fixed = T)),
          headerStyle = list(background = "#f7f7f8")),
    highlight = T,
    height = 1000,
    searchable = TRUE,
    defaultPageSize = 100)

現在、行が拡張され、credit$a が長い行にあります。

代わりに列を展開したい

このようなcssスタイリングを使用できることに注意してください

sticky_style <- function(left = TRUE) {
    style <- list(position = "sticky", 
                  fontWeight = "bold",
                  background = "#f7f7f8", 
                  zIndex = 1)
    if (left) {
      style <- c(style, list(left = 0, borderRight = "1px solid #eee"))
    } else {
      style <- c(style, list(right = 0, borderLeft = "1px solid #eee"))
    }
    style
}

reactable(credit,
          columns = list(
            a = colDef(
              style = sticky_style(),
              headerStyle = sticky_style(),
              minWidth = 200
            )),
    defaultColDef = colDef(
          header = function(value)
              str_to_title(gsub(".", " ",
                   gsub("_", " ", value, fixed = T),
                   fixed = T)),
          headerStyle = list(background = "#f7f7f8")),
    highlight = T,
    height = 1000,
    searchable = TRUE,
    defaultPageSize = 100)
4

0 に答える 0