Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

style_data_condtional - "row_index" won't accept vector of values #608

Closed
CanerIrfanoglu opened this issue Oct 1, 2019 · 1 comment · Fixed by #729
Closed

style_data_condtional - "row_index" won't accept vector of values #608

CanerIrfanoglu opened this issue Oct 1, 2019 · 1 comment · Fixed by #729
Labels
dash-type-enhancement New feature or request
Milestone

Comments

@CanerIrfanoglu
Copy link

I am using dashTable 4.0.2 and below is an example of highlighting multiple dashDataTable rows in Dash for R.

library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)

# Load data
data(mtcars)

# Create DashTable
carsDashDT <- dashDataTable(
  id = "cars-table",
  columns = lapply(colnames(mtcars),
                   function(colName){
                     list(
                       id = colName,
                       name = colName
                     )
                   }),
  data = df_to_list(mtcars),
  row_selectable = "multi",
)

# App Start ------------------------------

# Initate Application
app <- Dash$new()

# Create Layout ------------------------------

app$layout(
  htmlDiv(list(
    carsDashDT
  ))
)

# Callback Start ------------------------------

# Highlight dashTable rows
app$callback(
  output(id = "cars-table", property = "style_data_conditional"),
params = list(
  input(id = "cars-table", property = "selected_rows")
),

  function(rows) {
    style_data_conditional <- NULL

        for (i in 1:length(rows)) {
          rowIndex <- rows[[i]]
          style_data_conditional_append = list(list(
            "if" =  list("row_index" = rowIndex),
            "backgroundColor" = "#B0BED9"
          ))
          style_data_conditional <- c(style_data_conditional,
                                      style_data_conditional_append)
        }

    return(style_data_conditional)
  }
)

app$run_server()

The example provided at https://dashr.plot.ly/datatable/style under Conditional Formatting - Highlighting Certain Rows demonstrates how to highlight a single row with a numeric input.

Based on the example provided in the above link, I experimented with multiple different syntax but couldn't achieve highlighting multiple rows without using a loop.

The documentation for dashDataTable > style_data_conditional mentions:

row_index (numeric | a value equal to: 'odd', 'even'; optional)

It seems like row_index is currently limited to accepting single numeric input. It would be very nice to be able to apply conditional styles to multiple rows by feeding a vector/list of values. Rather than the loop in the callback, something similar to:

 style_data_conditional_append = list(list(
    "if" =  list("row_index" = rows)
))

In case I am missing it, I would appreciate if you can provide the correct syntax. Thanks.

@Marc-Andre-Rivet
Copy link
Contributor

row_index currently only supports a single index, not a list.

This would be useful indeed. Tagging for improvement.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dash-type-enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants