Replies: 3 comments
-
Hi, I'm trying to translate my teal app based on teal version < v.0.14 to the latest release v.0.15. The problem is with setting primary and foreign keys. I've read the materials + join key vignitte https://insightsengineering.github.io/teal.data/latest-tag/articles/join-keys.html#anatomy-of-join_keys but still I cannot figure out the issue of the app - it still throws an error that "extracted data has not correctly set joining keys" #I need to simply translate old code to teal migration:
app <- init(
data = teal_data(
dataset("x", x, keys=c("id"))
),
modules=modules(
tm_g_response("Response",
response = response2,
x = response1,
row_facet = NULL,
col_facet = data_extract_spec(
dataname = "x",
filter = filter_spec(
vars = vars,
choices = value_choices(x, vars$selected),
selected = value_choices(x, vars$selected),
multiple = T
)
),
coord_flip = FALSE
)
))
)
#I tried this but it didn't worked in v0.15.0:
data<- within(teal_data(), {
x=x
response1=response1
response2=response2
})
datanames <- c("x", "response1", "resposne2")
datanames(data) <- datanames
join_keys(data) <- join_keys(
join_key("x", keys = c("id")),
join_key("response1", keys = c("id")),
join_key("response2", keys = c("id")),
join_key("response1", "response2" keys = c("id"="id"))
)
app <- init(data=data,
modules=modules(
tm_g_response("Response",
response = response2,
x = response1,
row_facet = NULL,
col_facet = data_extract_spec(
dataname = "x",
filter = filter_spec(
vars = vars,
choices = value_choices(x, vars$selected),
selected = value_choices(x, vars$selected),
multiple = T
)
),
coord_flip = FALSE
)
)
)
I would appreciate your help |
Beta Was this translation helpful? Give feedback.
-
Hi @Mia-data
Would be easiest if you just send us the code of the former (working) application so we can help you directly - if it contains sensitive data please just replace sensitive information with some more implicit names/paths/symbols. It is hard to deduce from the code you've provided |
Beta Was this translation helpful? Give feedback.
-
Hi @gogonzo, I have opened also the issue here #1164 (comment) so I will continue provide more info there to avoid duplication of the topic. |
Beta Was this translation helpful? Give feedback.
-
Migrate from
TealData
toteal_data
The CRAN release of
teal
(v0.15.0) brings major changes the way data is created and processed byteal
, streamlining data flow acrossteal
modules and makingteal
packages much easier to maintain.The
data
argument inteal::init
no longer accepts theTealData
class, the basic data container is now theteal_data
class.We introduce a method for the base function
within
as a convenient way to run code within the data container.We also introduce the
teal_data_module
concept for cases when theteal_data
container must be built during the application run time.The table below shows how to adjust your existing apps to the new class and the following text that explains the changes in more detail.
Changes summary
Execute this code to obtain old `teal` (<=0.14.0) datasets `rADSL` and `rADTTE`. (click)
It is no longer necessary to specify code for individual datasets. 'teal.data::get_code()' can extract the code necessary to reproduce a specific dataset, using the `datanames` argument.
Create simple data
Until now, supply data to a
teal
application was a multi-step process, where one would pass data objects to thedataset()
function to create "datasets" and then include the datasets toteal_data()
to create the final data container.Now data objects are passed directly to
teal_data()
.Note that this way of specifying data is recommended only in case where no reproducible code is necessary.
Including data in
teal
applications is detailed in this vignette.Create reproducible data
Tracking code for reproducibility requires that the data creation code be included in the
teal_data
object.In old
teal
this was done by creating data objects by running code in the global environment and then passing both the objects and the code toteal_data()
.While this is still possible, we recommend the superior approach of initializing
teal_data
as an empty container and creating data objects by running code within the container.Keeping the data in an isolated environment from the moment of creation throughout the whole analysis is the best way ensure that the code represenst the data exactly.
A detailed explanation of reproducibility can be found in this vignette.
Access data
The new
teal_data
class stores data objects much like a list.Objects can be accessed using public functions exported from hte underlying
teal.code
package.Modify data
The functions
mutate_data
andmutate_dataset
are superseeded bywithin
.The usage of the functions is similar but
within
accepts inline R expressions rather thancharacter
.(If there is a valid reason to pass code as character, use the
eval_code
function instead ofwithin
.)Note that it is no longer necessary to which data object the code refers to.
The expression is evaluated and changes are directly applied to the contents of the container.
within
also works withteal_data_module
(more on that later).Please visit the "Introduction to teal.data" vignette for more details.
Data validation
The old
TealData
class had adata$check()
method which was used to validate that the code corresponds to the data.The check was done by evaluating the code and comparing the results to the data stored in the object.
This action is now performed by the
verify
function, defined in theteal.data
package.The verification process is described in detail in the
teal_data
reproducibility vignette.Join keys
Join keys are now accessed and set with the
join_keys
function.Running
join_keys
on ateal_data
object returns a list of joining keys.Modifying part of a joining key set is done with the
[
operator.A detailed explanation of joining keys can be found in the "Join Keys" vignette.
Connectors
All hitherto existing connector classes and their related functions are now deprecated and we do not offer 1:1 replacements.
The old
Teal*
classes containeddata
,ui
,server
and various other attributes and methods.That solution was not flexible enough to fullfil incoming user requests and also hampered maintenance.
Intead we introduce the
teal_data_module
concept.A special
shiny
module is created with theteal_data_module
function.The module is passed to a
teal
application in place of ateal_data
object and creates data once the application starts.The server function runs all code necessary to connect to an external data source and obtain the desired data objects and returns a
teal_data
object.teal_data_module
is thoroughly explained in the "Data as shiny module" vignette.Beta Was this translation helpful? Give feedback.
All reactions