Color Coding DT rows without rerendering a table


Shiny App function:
My shiny app’s function built to allow users to classify rows into 3 different buckets. Once they select and classify a row, the row color changes. In order to accomplish this, I created a vector in the dataframe that is used by the DT to store the classification.

By creating the the vector and using formatStyle, I need to have users modify that vector and therefore modify the dataframe. This causes the table to re-render each time a classification is made.

Is there a method to color code rows that does not involve formatStyle or a way to use formatStyle such that I do not need to keep hitting <- renderDataTable


output$table <- renderDataTable({
dt <- isolate(reactive_value$dt)
} else{
dt <- read.csv(isolate(reactive_value$filename))
dt$classification <- "class4"
reactive_value$dt <- dt
            extensions = extensions,
            ) %>%
    formatStyle("classification", target = "row",backgroundColor = styleEqual(c('class1', 'class2','class3'), c("col1", 'col2', 'col3')))

_classification example_
 dt <- isolate(reactive_value$dt)
 dt$classification[row.names(dt)[input$table_rows_selected]] <- "class1"
 reactive_value$dt <- dt


@arifyali I’ve been speaking to some colleagues about this… I think it may not be possible to make work in the way you want.

From my colleague: “The tricky thing is that styling tables (e.g., via formatStyle()) is based on row callbacks: but DataTables does not have the API to change or reset the callbacks, so there is no (straightforward) way to change the styling on the fly.”

Sorry! It’s possible that there could be a non DataTable approach (maybe with RHandsonTable, though this is just a guess) would allow what you’re trying to do. In my experience, though, get “refresh without re-render” feature-set is very limited.