简体   繁体   English

将 R 中 DT 表中的值向左移动

[英]Move values in DT table in R shiny towards left

In DT table/datatable in R shiny.在 R 闪亮的 DT 表/数据表中。 When there is no data available.当没有可用数据时。 There is sentences telling "No data available".有句子告诉“无可用数据”。 Wanted to check if we can move this sentence towards left.想检查我们是否可以将这句话向左移动。 Currently it is displayed in the center目前它显示在中心

can anyone please help?有人可以帮忙吗?

Below is the part from Rshiny以下是来自 Rshiny 的部分

output$table <- DT::renderDT({

    datatable(data2(......)) 
    })

You have to change the td.dataTables_empty CSS.您必须更改td.dataTables_empty CSS。

Outside Shiny, you can do:在 Shiny 之外,您可以执行以下操作:

library(DT)

dat <- data.frame(X = numeric(0), Y = numeric(0))

callback <- '$("td.dataTables_empty").css("text-align", "left");'

datatable(dat, callback = JS(callback))

This also works inside Shiny (declare callback where you want, eg at the beginning of the app).这也适用于 Shiny(在您想要的地方声明callback ,例如在应用程序的开头)。 But inside Shiny you can also change the CSS like this:但是在 Shiny 中,您还可以像这样更改 CSS:

library(shiny)
library(DT)

dat <- data.frame(X = numeric(0), Y = numeric(0))

css <- "td.dataTables_empty {text-align: left !important;}"

ui <- fluidPage(
  tags$head(tags$style(HTML(css))),
  DTOutput("dtable")
)

server <- function(input, output, session){

  output[["dtable"]] <- renderDT({
    datatable(dat)
  })
}

shinyApp(ui, server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM