Dynamically create dataframe based on user given data

,

I want to create a dataframe with columns names given by user.
Like I have some textInputs(name1, name2 etc) and textInputs(value1, value2 etc).
Now I want to create dataframe with entries in name1, name2 as column names and corresponding entries in value1, value2 as dataframe entries.

How can I do this.

You could do it as in the following code. In a shiny app the elements of input would come from the widgets and not be coded in the way I show but the principle would be the same.

input <- list()
input$name1 <- "X"
input$name2 <- "Y"
input$value1 <- "THIS"
input$value2 <- "THAT"
DF <- data.frame(input$value1, input$value2)
colnames(DF) <- c(input$name1, input$name2)
DF
#>      X    Y
#> 1 THIS THAT

Created on 2019-12-17 by the reprex package (v0.3.0.9000)

User have to enter this, that, X,Y from the ui. I am not asking to hard code this. textInputs means the Text-Box which will take entries from the user.

Yes, I understood that the actual inputs would come from the user. That is the meaning of "In a shiny app the elements of input would come from the widgets and not be coded in the way I show"
Here is an example

library(shiny)

ui <- fluidPage(
  fluidRow(
    textInput("name1", "Name 1"),
    textInput("name2", "Name 2"),
    textInput("value1", "Value 1"),
    textInput("value2", "Value 2")
    ),
  fluidRow(
    tableOutput("Tbl")   
  )
)


server <- function(input, output) {
    output$Tbl <- renderTable({
      DF <- data.frame(input$value1, input$value2)
      colnames(DF) <- c(input$name1, input$name2)
      DF
    })
}

shinyApp(ui,server)

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