2

请参阅下面一个非常简单的 R 闪亮应用程序,它呈现可反应。

https://kormir.shinyapps.io/reactable_example/

library(shiny)
library(reactable)
ui <- fluidPage(
  
  tags$head(tags$style(HTML('.ReactTable {border-collapse:collapse; }
                 .ReactTable .rt-thead .rt-td, .ReactTable .rt-thead .rt-th {
                   height: 200px;
                   word-wrap: break-word;
                   transform:
                     translate(10px, -25px)
                     rotate(-80deg);
                 }'))),
  
  reactableOutput('rt') 
  
)

server <- function(input, output) {
  
  output$rt <- renderReactable({
    reactable(mtcars[1:4,1:5], fullWidth = F)
  })
  
}

# Run the application 
shinyApp(ui = ui, server = server)

在 tags$head 中,您可以看到我尝试旋转标题,但结果很糟糕:

结果

有没有更简单的方法来正确旋转标题?

谢谢

4

1 回答 1

4

不确定您的预期结果如何,但如何:

library(shiny)
library(reactable)

ui <- fluidPage(reactableOutput('rt'))

server <- function(input, output) {
  output$rt <- renderReactable({
    reactable(
      mtcars[1:4, 1:5],
      fullWidth = F,
      defaultColDef = colDef(
        align = "center",
        minWidth = 70,
        headerStyle = list(
          `white-space` = "nowrap",
          `transform-origin` = "50% 50%",
           transform = "rotate(-90deg)",
          `margin-top` = "10px",
          `margin-bottom` = "10px",
           borderColor = "#ffffff"
        )
      )
    )
  })
  
}

shinyApp(ui = ui, server = server)

结果

这个答案对到达这里很有用。

于 2022-01-21T14:30:46.583 回答