Why are my column names not changing when I set the colnames in DT datable and giving me an error that ' names in the 'escape' argument not found'?

J.Sabree

I want to change how my column names are displayed in my R Shiny App's datable, but I do not want to change how R responds to them under the hood. When I try using datatable's colnames argument, I get the following error:

Warning: Error in convertIdx: Some column names in the 'escape' argument not found in data

Which, technically, makes sense because I am changing the column names, but I thought that this was just an aesthetic change (and that's what I want).

Here's a simple app that reproduces the error:

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)
Ronak Shah

The order in columns need to be opposite, it is newname = oldname.

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"))
  }) 
  
  output$table <- DT::renderDataTable({
    datatable(raw_data(),
              colnames = c("Date to Start" = "start_date", "Letter Options" = "choice"))
  })
}

shinyApp(ui = ui, server = server)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using set_names vs. mutate(colnames) when changing data frame column names to lower case

Why my code giving me a stackdump error when I run it?

Changing column names of a matrix in R without using colnames()

Colnames() prints column names in rows, I want single column

I want to update my column attributes names without changing their values

R : Changing variable names with a for(); grepl() and colnames()

Why does my pip install requests giving me an error when i install it?

Why is Xquery giving me an error on my variable? I

Why is my dataframe using column names I did not assign?

I have created two tables and below column names are 100% correct,But it giving me like below

Changing column names when appropriate and ignoring in inapplicable

tidyverse rename_with giving error when trying to provide new names based on existing column values

Changing multiple column names

Hide the column names in DT::datatable()

Why is Paypal giving an error when I run my subscription form?

Why is python giving an error when I play my second sound

Why is vscode giving me the error "No Inputs where found in file tsconfig.json" when tsc found none?

in forms.py when i set "to_field_name" to more than one column name, it's giving me error

why is my code giving me a settext error?

Why is my conditional operator giving me an error?

Why is my SKAudioNode giving me an error?

How do I set argument names and types for a function argument in TypeScript?

Set column names when stacking pandas DataFrame

I clearly see a positional argument defined, so why is it giving me this error?

Why is my JSON serializer giving a 500 error when changing property from byte[] to List<byte[]>?

How do I escape database table and column names for PostgreSQL in VBA?

Will changing the column names in SQL Server have an effect on my SSIS packages?

Why doesn't R change column names when I am trying to change all column names based on a single row?

Why is my JavaScript code giving giving a reference error when I have defined the property inside the object?