首页 > 解决方案 > 更改闪亮数据表中的列名

问题描述

我正在尝试更改闪亮数据表的列标题。这是我到目前为止所做的。我在服务器部分的代码中添加了注释。我正在尝试更改列名并将行的选择限制为单个。

 addr <- as.data.table(read.csv("addresses.csv", header = T, stringsAsFactors = F)

ui <- fluidPage(
  br(),
  fluidRow(
    column(12, div(DT::dataTableOutput("addressTable"), style="font-family:verdana", align="left"))
  ),
  fluidRow(
    column(4, div(textOutput("selectedAddress"), align="center"))
  )
)

server <- function(input, output) {
      # output$addressTable <- DT::renderDataTable({
      #   names(addr) [1:4]<- c("STREET ADDRESS","CITY NAME","PROVINCE","POSTAL CODE")
      #   addr
      # }) -- This code works, I was able to change the column headers but not able to add the selection single option.

      output$addressTable <- DT::renderDataTable(addr, selection = 'single') - this code works with the selection to single, but not able to change column headers.

}    
shinyApp(ui, server)

标签: rshiny

解决方案


推荐阅读