how to change the name of a column in my dataframe according to my choice of selectInput?

hi, how to change the name of a column in my dataframe according to my choice of selectInput?

example: change in the dataframe the name of the column "Number" by "Childbirth".Capture
.thank you for helping me

Hi,

It confuses me a bit why you want to do this, because just changing the name of a certain column won't change any of the other data, but if that's all you want to do here is an example:

library(shiny)

ui <- fluidPage(
  titlePanel("My App"),
  selectInput("myInput", "Choose", choices = paste0("ColumnName", 1:5)),
  tableOutput("myTable")
)

server <- function(input, output, session) {
  
  myData = reactive({
    myData = data.frame(x = 1:10, y = LETTERS[1:10])
    colnames(myData)[2] = input$myInput
    myData
  })
  
  output$myTable = renderTable({
    myData()
  })
  
}

shinyApp(ui, server)

Hope this helps,
PJ

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.