Reacting to Data Table Filtered Data

Hi, I'm currently trying to have the mean of a column change based on what someone does in the data filter of a data table, but I'm confused as to how I would do this (there aren't any inputs to react off of. Here is the relevant code from the server, which is wrong (The mean for the original data will work, not the filtered data). EDIT: Sorry, I should have include what I did in the UI. Here it is:

dataTableOutput("CO2Table")
server <- function(input, output) {
    reactedData = CO2
    data = CO2
    output$CO2Table <- renderDataTable({ 
        data
        reactedData = data.frame(data)
    },
    filter = 'top',
    rownames = FALSE,
    options = list(autoWidth = TRUE, columnDefs = list(list(width= '200px', targets="_all"))))
    
    
    output$text_example = renderText({paste("Mean: ", mean(reactedData$conc))})
}

If you want to make reactive variables in the server you need to use reactiveVal or similar. e.g.

data <- reactiveVal(CO2)

Now CO2 is the initial value of data(). You can change the value of data() using data(newvalue) and data() will be a reactive variable which will trigger reactivity.

reactiveValues is an alternative similar thing that allows you to have a list of reactive values.

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