我想改变我的列名在R Shiny App的datable中的显示方式,但我不想改变R在后台对它们的响应方式。当我尝试使用datatable的colnames
参数时,我得到以下错误:
Warning: Error in convertIdx: Some column names in the 'escape' argument not found in data
从技术上讲,这是有意义的,因为我改变了列名,但我认为这只是一个美学上的改变(这就是我想要的)。
下面是一个简单的应用程序,它可以重现错误:
library(shiny)
library(dplyr)
library(DT)
ui <- fluidRow(
column(12,
DT::dataTableOutput("table")
)
)
server <- function(input, output) {
raw_data <- reactive({tibble(start_date = c("2020-01-01", "2020-01-09", "2020-01-30"),
choice = c("A", "B", "C"))
}) #Note: I'm aware this doesn't need to be reactive here, but in my actual data, the underlying data are reactive, so I want to mirror my real world scenario here.
output$table <- DT::renderDataTable({
datatable(raw_data(),
colnames = c("start_date" = "Date to Start", "choice" = "Letter Options"))
})
}
shinyApp(ui = ui, server = server)
1条答案
按热度按时间alen0pnh1#
columns
中的顺序需要相反,它是newname = oldname
。