Rename column names in Rhandsontable inside render funtion

Is there a way to rename column names here in iris dataset inside render funtion. I mean if the column name is Species , then new column names should be "Category" and similarly for Petal.Width, it should be New.petal.width

---
title: "Untitled"
runtime : shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(rhandsontable)
```

Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
rHandsontableOutput("table")
output$table <- renderRHandsontable(rhandsontable(iris))
```
library(tidyverse)
rHandsontableOutput("table")
output$table <- renderRHandsontable(rhandsontable(rename(iris,
                                                         "Category"=Species,
                                                         "New.petal.width"=Petal.Width)))

Perfect thanks a lot....

Hi Nir. Thanks a lot for the help. but I found 1 strange this. I am not able to change the name of Petal.Length if I add hot_col("Petal.Length", readOnly = FALSE, allowInvalid = TRUE). I get the error attempt to select less than one element in get1index

Below code for reference. Is there a way to rename Petal.Length also? Also may I know why I get this error?

output$table <- renderRHandsontable(rhandsontable(rename(iris,
                                                         "Category"=Species,
                                                         "New.petal.width"=Petal.Width, "New.petal.length"=Petal.Length)) %>% hot_col("Petal.Length", readOnly = FALSE, allowInvalid = TRUE))

I've not used hot_col so don't know what it does but if you are trying to name petal length you should use the new name for it that you have it before you use hot col.
In other words in hot col you use an old name so it's not there.

1 Like