Shiny - passing column headers from a dynamic function

Hello RStudio Community,
I'm learning to use Shiny, and could use some guidance. I'd like the user to be able to dynamically select variables (columns) from a .csv file, and then dynamically generate sliders or numeric input fields which, in turn, would generate a dataframe. However, I need the new data frame to have the exact same header values as the original .csv file that was uploaded. below is a code snippet from my R.Server code. It appears to generate the dataframe, but it I am so far unable to generate (or change) the column headers of the new dataframe. Any ideas? (I also cannot seem to pass the column header names to the numericinput fields - these seem to be related issues)
sincerely,
very stuck.

...

output$input_ui <- renderUI({                             #this creates dynamic numeric inputs based on the 
variables selected by the user
pvars <- df_sel()                                              #df_sel() is a function where the user selects the variables they want from the .csv file
varn = names(df_sel())
lapply(seq(pvars), function(i) {                        #dynamically creates numeric inputs fields based on pvars (number of variables selected)
  numericInput(inputId = paste0("range", pvars[i]),
               label = varn,
               value = 0)
})

})

numbers <- reactive({                            #this creates a reactive dataframe for the numbers
pvars <- df_sel()                                    #this sets pvars to the number of variables the user selected earlier
num = as.integer(ncol(pvars))                          #changes it to an integer
print(num)                                                         #checks that num is an integer
pred <- data.frame(lapply(1:num, function(i) {  #creates a data frame and passes in the values from numericinput above 
  input[[paste0("range", pvars[i])]]
  
}))

n = input$months  #Since I want a dataframe of repeating values, this pulls that number from a slider already created in the UI section
pd = data.frame(pred, i=rep(1:n,ea=NROW(input$months)))
pd[1:(length(pd)-1)]
#colnames(pd, c(df_sel()))  #this does not seem to work at all!!!  
})
 
output$table1 <- renderTable({  
numbers()
fv = numbers()
print(dim(fv))  #check the dimensions of the table
print(fv) # chcek the table is populating correctly.
   
})

...

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