闪亮:DT中的复选框使行更换高度

发布于 2025-02-12 04:21:31 字数 857 浏览 0 评论 0原文

我正在r Shiny DT中实现一些复选框,但是由于某些原因,复选框似乎包含在一个比单元格本身高的盒子中,因此我最终以非常不愉快的布局为止,距离少于同一页面。

是否有一种方法可以控制复选框或其他组件包含道具的高度,以修复单元格?复选框本身比实际单元格小得多,并且可以完全适合正常单元。

在某些代码下面,如果您想播放问题,可以重现问题。

library(DT)

ui <- basicPage(
  h2("The mtcars data"),
  DT::dataTableOutput("mytable")
)

server <- function(input, output) {
  
  shinyInput <- function(FUN, len, id, ...) {
    inputs <- character(len)
    for (i in seq_len(len)) {
      inputs[i] <- as.character(FUN(paste0(id, i), ...))
    }
    inputs
  }
  
  mtcars <- data.frame(mtcars, newvar=shinyInput(checkboxInput,nrow(mtcars),"chkbx_",label="",value=TRUE,width=NULL))
  
  output$mytable = DT::renderDataTable({
    DT::datatable(mtcars, escape = FALSE, selection = 'none', options = list(searching = FALSE, ordering  = FALSE))
  })
  
}

shinyApp(ui, server)

I am implementing some checkboxes in R shiny DT, however for some reasons it seems like the checkbox is contained in a box higher than the cell itself, so I am ending up with a very unpleasant layout as far less rows fit the same page.

Is there a way to control the height in which the checkbox or other components as props are contained, in order to fix the cell? the checkbox itself is much smaller than the actual cells and would fit perfectly in a normal cell.

below some code to reproduce the problem if you want to play with it.

library(DT)

ui <- basicPage(
  h2("The mtcars data"),
  DT::dataTableOutput("mytable")
)

server <- function(input, output) {
  
  shinyInput <- function(FUN, len, id, ...) {
    inputs <- character(len)
    for (i in seq_len(len)) {
      inputs[i] <- as.character(FUN(paste0(id, i), ...))
    }
    inputs
  }
  
  mtcars <- data.frame(mtcars, newvar=shinyInput(checkboxInput,nrow(mtcars),"chkbx_",label="",value=TRUE,width=NULL))
  
  output$mytable = DT::renderDataTable({
    DT::datatable(mtcars, escape = FALSE, selection = 'none', options = list(searching = FALSE, ordering  = FALSE))
  })
  
}

shinyApp(ui, server)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花坊 2025-02-19 04:21:31

您需要修改应用程序的CSS,以实现此目标。最快的解决方案是将样式标签添加到UI:

ui <- basicPage(
  tags$style(HTML("
     td > div.form-group > div.checkbox { 
        margin: 0px; 
     }
                  
     td > div.form-group {
        margin: 0px;
     }             
                  
  ")),
  h2("The mtcars data"),
  DT::dataTableOutput("mytable")
)

这将从应用程序单元格中的所有表格组和复选框中删除边距。

You need to modify CSS of the app in order to achieve this. The quickest solution is to add a style tag to your UI:

ui <- basicPage(
  tags$style(HTML("
     td > div.form-group > div.checkbox { 
        margin: 0px; 
     }
                  
     td > div.form-group {
        margin: 0px;
     }             
                  
  ")),
  h2("The mtcars data"),
  DT::dataTableOutput("mytable")
)

This will remove margins from all form-groups and checkboxes inside table cells in the app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文