Multiple datatables from one reactive data frame in R shiny


I have a very large reactive data frame based on user inputs in R shiny called newdata().

How can I use this same reactive data frame, but only specific columns to make new datatables?

I want to make a few new data tables which only have 4 columns from newdata() rather than all 20.


5.4 Select columns with select()
It’s not uncommon to get datasets with hundreds or even thousands of variables. In this case, the first challenge is often narrowing in on the variables you’re actually interested in. select() allows you to rapidly zoom in on a useful subset using operations based on the names of the variables.

5 Data transformation | R for Data Science (

Does select still work if you are referring to a reactive dataframe? That is the trouble that I seem to be running into-- I'm not sure where I would put a select-- say if I wanted to only include variables 1-3. here is a brief example below!

  newdata <- reactive({
    ##make many new variables needed for all of the charts, maps, and plots 
    ##new variables based on user input
    ##new variables based on user input
    Var1 <- as.numeric(input$variable1)
    Var2 <- as.numeric(input$varable2)
    dataset$'Total'<- Var1 + Var2 

colnames(newdatadata)<- c("Variable 1 ", "Variable 2", "Variable 3", "Variable 4", "Variable 5", "Variable 6", "Variable 7")


  output$datatable1 <- renderDataTable(newdata(),options = list(
    searching = FALSE,
    pageLength = 10,
    lengthMenu = c(5, 10, 15, 20)))

Yes, it does. I often use it for that purpose.

So in the above example, if I am referring to the reactive dataframe "newdata ()" in a plot or table, where would i add the select?

Would it be within the reactive data object?

like this:

select (newdata(), Variable 1, Variable 2)

Again, thank you!

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.