2

I have created an .qmd file in R which contains a table created using the excellent reactable package.

How can I change the data contained in this table using only javascript?

I know that something similar can be done using crosstalk or shiny, but I want to know specifically how to do this using only javascript.

Here is a example .qmd reprex that describes the problem:

---
title: "update reactable"
format: html
---

```{r}
library(reactable)

ojs_define(iris1 = iris[1:5,],
           iris2 = iris[51:52,],
           iris3 = iris[101:104,])

reactable(iris[1:5,],
          elementId = 'iris')

```

```{ojs}
viewof choice = Inputs.radio(['a','b','c'], {label: 'choose a dataset', value: 'a'})

```

```{ojs}
datasets = ({'a': iris1,
            'b': iris2,
            'c': iris3
            })

dataset = datasets[ choice];

dataset

```

```{ojs}
"update reactable instance based on user's choice here"
// update reactable instance based on user's choice here

```

Thanks

michael
  • 153
  • 1
  • 11

1 Answers1

1

Reached out to the maintainer of the reactable package who has graciously added this functionality in v0.3.0.9000

See this example: https://glin.quarto.pub/observable-reactable/

michael
  • 153
  • 1
  • 11