Convert teal_data
to tdata
in teal
modules.
Details
Recent changes in teal
cause modules to fail because modules expect a tdata
object
to be passed to the data
argument but instead they receive a teal_data
object,
which is additionally wrapped in a reactive expression in the server functions.
In order to easily adapt such modules without a proper refactor,
use this function to downgrade the data
argument.
Examples
td <- teal_data()
td <- within(td, iris <- iris) %>% within(mtcars <- mtcars)
td
#> ✅︎ verified teal_data object
#> <environment: 0x563c05d345e8> [L]
#> Parent: <environment: devtools_shims>
#> Bindings:
#> • mtcars: <df[,11]> [L]
#> • iris: <df[,5]> [L]
as_tdata(td)
#> $iris
#> reactive({
#> x[[dataname]]
#> })
#>
#> $mtcars
#> reactive({
#> x[[dataname]]
#> })
#>
#> attr(,"code")
#> reactive({
#> teal.code::get_code(x)
#> })
#> attr(,"join_keys")
#> An empty join_keys object.
#> attr(,"class")
#> [1] "tdata" "list"
as_tdata(reactive(td))
#> $iris
#> reactive({
#> x()[[dataname]]
#> })
#>
#> $mtcars
#> reactive({
#> x()[[dataname]]
#> })
#>
#> attr(,"code")
#> reactive({
#> teal.code::get_code(x())
#> })
#> attr(,"join_keys")
#> An empty join_keys object.
#> attr(,"class")
#> [1] "tdata" "list"