It's possible to conditionally format a selected cell in Reactable's shiny framework by setting two input$ values to the selected cell's data but in the comparison function to then change the format of this cell, it can take a very long time for large tables.
This is likely because the way I'm going about it is searching the whole table for something that matches the input$ values. Is there a more speed efficient way to do this? You can try by running this first and then uncommenting out the replication function and seeing how much slower it becomes.
library(shiny)
library(reactable)
data <- MASS::road[11:17, ]
data <- tibble::rownames_to_column(data, "state")
#data <- do.call("rbind", replicate(100, data, simplify = FALSE))
ui <- fluidPage(
titlePanel("reactable example"),
reactableOutput("table")
)
server <- function(input, output, session) {
output$table <- renderReactable({
reactable(
data,
defaultColDef = colDef(
style = function(value, index, name) {
if (!is.null(input$col)) {
print(paste0("Col: ", input$col$index))
print(paste0("Row: ", input$row$index))
print(paste0("Index: ", index))
print(paste0("Name: ", name))
print(paste0("Value: ", value))
if (input$col$index == name &&
input$row$index == data[index, "state"]) {
list(fontWeight = "bold")
}
}
}
),
onClick = JS("function(rowInfo, column) {
if (window.Shiny) {
Shiny.setInputValue('row', {index: rowInfo.values.state})
Shiny.setInputValue('col', {index: column.name})
}
}"),
)
})
}
shinyApp(ui, server)