问题
I've been trying to vertically align the elements inside a dataframe rendered by dt, to do this I used the className = "dt-center" arguments inside the options of the datatable function, while this works for most of the elements of my dataframe, it does not center the numericInput inside it.
I tried to use the "vertical-align" = "middle" css argument with the formatStyle function, but this does not change the alignment of the numericInput either.
Would there be a way to align these numericInput like the rest of the text?
EDIT: Added a screenshot of the desired alignment
library(shiny)
shinyInput <- function(FUN, len, id, ...) {
  inputs <- character(len)
  for (i in seq_len(len)) {
    inputs[i] <- as.character(FUN(paste0(id, i), ...))
  }
  inputs
}
df <- iris
df$num <- shinyInput(numericInput, nrow(df), "num_", label = NULL, value=NULL)
ui <- dashboardBody(box(fluidPage(DT::dataTableOutput('DTdf'))))
server <- function(input, output){
  dfDT <- reactive({df})
  
  output$DTdf <- DT::renderDT({
    datatable(dfDT(),
              escape=F,
              editable="all",
              options = list(
                columnDefs = list(list(className = "dt-center", targets="_all")),
                preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
                drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } '))) %>%
      formatStyle(c(6), "vertical-align" = "middle")
    })
}
shinyApp(ui=ui, server=server)
    回答1:
The number inputs are shifted up because of a bottom margin. You can remove it with the help of CSS:
CSS <- HTML("td .form-group {margin-bottom: 0;}")
ui <- dashboardBody(
  tags$head(tags$style(CSS)),
  box(
    fluidPage(
      DT::dataTableOutput('DTdf')
    )
  )
)
    来源:https://stackoverflow.com/questions/64277527/vertical-alignment-of-numericinput-in-dt