'Change column name in R shiny

I have problem with change name of column in dataset df1(). I prepare selectInput (column name to rename) and textInput (target column name). But my version doesn't work (code below). Better said, it works, but only with "static" new colname, when i use textInput it thorws me an error unexpected '='. Can somebody help me ?

SERVER:
  output$to_rename<- renderUI({
    choice <- names(df1())
    selectInput('to_rename', label = 'Choose column to rename: ', choices = choice)
  })
  
  output$target_rename<- renderUI({
    textInput('target_rename', label = 'Write new column name: ', value = "Your_new_colname")
  })
  
  observeEvent(input$ren_col, {
    df1(df1() %>% rename(
      input$target_rename = input$to_rename   #when I use: new_name = input$to_rename it works 
#and selected column will be rename to "new_name"
    ))
  })

##############################################################################

UI:
uiOutput("to_rename"),
uiOutput("target_rename"),
actionButton("ren_col", "Rename"),


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source