Skip to content

Commit eb91afd

Browse files
committed
Update tables when reactive meta values change; add meta to dataKey
1 parent f250640 commit eb91afd

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* Fixed `JS()` not working when `htmlwidgets` 1.6.3 or later is installed. ([#348](https://github.com/glin/reactable/issues/348))
3838
* In `reactableTheme()`, `stripedColor` and `highlightColor` now work when using sticky columns. (@grcatlin, [#401](https://github.com/glin/reactable/issues/401))
3939
* In Crosstalk tables, pagination no longer resets when selecting a row on a page greater than 1. (@msaltieri, [#349](https://github.com/glin/reactable/issues/349))
40+
* In Shiny apps, tables now update correctly when reactive `meta` values change. (@khusmann, [#416](https://github.com/glin/reactable/issues/416))
4041

4142
## Breaking changes
4243

R/reactable.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ reactable <- function(
716716

717717
# Create a unique key for the data. The key is used to fully reset state when
718718
# the data changes (for tables in Shiny).
719-
dataKey <- digest::digest(list(data, cols))
719+
dataKey <- digest::digest(list(data = data, columns = cols, meta = meta))
720720

721721
# Serialize user-set args only to keep the widget HTML slim
722722
defaultArgs <- formals()

tests/testthat/test-reactable.R

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test_that("reactable", {
4848
expected <- list(
4949
data = data,
5050
columns = columns,
51-
dataKey = digest::digest(list(data, columns)),
51+
dataKey = digest::digest(list(data = data, columns = columns, meta = NULL)),
5252
static = FALSE
5353
)
5454
expect_equal(attribs, expected)
@@ -90,7 +90,7 @@ test_that("reactable", {
9090
className = "tbl",
9191
style = list(color = "red"),
9292
inline = TRUE,
93-
dataKey = digest::digest(list(data, columns)),
93+
dataKey = digest::digest(list(data = data, columns = columns, meta = NULL)),
9494
static = FALSE
9595
)
9696
expect_equal(attribs, expected)
@@ -213,6 +213,20 @@ test_that("data supports Crosstalk", {
213213
expect_equal(attribs$crosstalkGroup, data$groupName())
214214
})
215215

216+
test_that("dataKey", {
217+
df <- data.frame(x = 1)
218+
tbl <- reactable(
219+
df,
220+
columns = list(x = colDef(cell = function(value) value)),
221+
meta = list(m = "data")
222+
)
223+
attribs <- getAttribs(tbl)
224+
expect_equal(
225+
attribs$dataKey,
226+
digest::digest(list(data = attribs$data, columns = attribs$columns, meta = attribs$meta))
227+
)
228+
})
229+
216230
test_that("columns", {
217231
df <- data.frame(x = 1)
218232
expect_error(reactable(df, columns = "x"), "`columns` must be a named list of column definitions")

0 commit comments

Comments
 (0)