Color Coding DT rows without rerendering a table


#1

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.

Problem
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.

Question
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

Code

output$table <- renderDataTable({
if(!is.null(reactive_value$dt){
dt <- isolate(reactive_value$dt)
} else{
dt <- read.csv(isolate(reactive_value$filename))
dt$classification <- "class4"
reactive_value$dt <- dt
}
 datatable(dt,rownames=F,
            filter='top',
            extensions = extensions,
            options=options,
            ) %>%
    formatStyle("classification", target = "row",backgroundColor = styleEqual(c('class1', 'class2','class3'), c("col1", 'col2', 'col3')))
})

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