Skip to content

remove datasets and chunks - #75

Closed
mhallal1 wants to merge 13 commits into
mainfrom
61_data_merge_dependency@main
Closed

mhallal1 wants to merge 13 commits into
mainfrom
61_data_merge_dependency@main

Conversation

@mhallal1

@mhallal1 mhallal1 commented Jun 17, 2022 •

Copy link
Copy Markdown
Contributor

closes #61

Dependency on datasets and chunks has been removed from data merge module is such a way:

  1. New modules merge_expression_module and merge_expression_srv which are the new versions of data_merge_module and data_merge_srv. The new modules have data instead of datasets as argument and an additional argument join_keys.
  2. Merge_datasets is modified to use data instead of datasets and chunks was completely removed from it. It now returns a list of expr, columns_source, key and filter_info. No data or chunks are returned anymore. Be aware that expr now is a list of calls instead of character.
  3. get_dplyr_call and get_merge_call have been modified accordingly.
  4. data_merge_srv has been modified in a way to use the same merge_datasets, get_dplyr_call and get_merge_call scripts. It defines data and join_keys internally and calls merge_expression_srv where it appends data and chunks to the returned list.

Please test with the example apps in merge_expression_module.R and data_merge_module.R. Note that we still need datasets so far as it is still used in data_extract until this is done #67

The design of the apps would be like this now:

server = function(input, output, session) {
#initialize chunks
chunks_h <- teal.code::chunks_new()

#push data in chunks

#call data_merge
merged_data <- merge_expression_srv(
      selector_list = selector_list,
      data = data_list,
      join_keys = join_keys,
      merge_function = "dplyr::left_join"
    )

#push data_merge code in chunks
ch_merge <- reactive({ 
      ch <- teal.code::chunks_deep_clone(chunks_h)
      for (chunk in merged_data()$expr) teal.code::chunks_push(chunks = ch, expression = chunk)
      ch$eval()
      ch
    })

#get output from chunks

}

@mhallal1 mhallal1 added the core label Jun 17, 2022
Comment thread R/data_merge_module.R Resolved
@mhallal1 mhallal1 mentioned this pull request Jun 17, 2022
4 tasks done
@gogonzo gogonzo self-assigned this Jun 20, 2022

@kpagacz kpagacz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is a draft, and comments on drafts are sometimes annoying, but I think it is better to say this early.

Why do these new functions need to be a shiny module?

They do not use chunks, so no point in using anything from the session object, and I just checked that input is not used anywhere in merge_datasets.

Is there any other reason why we insist on making it a shiny module?

Comment thread R/data_merge_module.R Resolved
Comment thread R/merge_datasets.R
},
expr = all_call_string,
chunks = chunks_stack,
expr = all_calls_expression,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expr here is a list. I'd suggest to return expression instead, as expression can be evaluated with single expr call. In case of list we need for(i in expr) eval(expr).

expr <- c(
  as.expression(quote(ADSL <- 2)),
  as.expression(quote(ADTTE <- 3))
)
expr
# expression(ADSL <- 2, ADTTE <- 3)

as.character(expr)
# [1] "ADSL <- 2"  "ADTTE <- 3"

eval(expr)
ls()
# [1] "ADSL" "ADTTE"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively you can also convert whole vector instead of each elements:

as.expression(c(quote(ADSL <- 1), quote(ADTTE <- 2)))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see but the consequence is that the code will be rendered as one big expression in the SRC (below) hence this approach was not used:
Screenshot from 2022-06-28 10-24-02

Comment thread R/merge_expression_module.R Resolved
@gogonzo

gogonzo commented Jun 21, 2022 •

Copy link
Copy Markdown
Contributor

Why do these new functions need to be a shiny module?

We need shiny module because selector_list is a reactive. Also join_method can be reactive. Of course simple function can also use reactive objects, but this gives us possibility to make merge_expr_ui also.

@kpagacz

kpagacz commented Jun 22, 2022 •

Copy link
Copy Markdown
Contributor

Why do these new functions need to be a shiny module?

We need shiny module because selector_list is a reactive. Also join_method can be reactive. Of course, simple functions can also use reactive objects, but this gives us possibility to make merge_expr_ui also.

I can't imagine why we would like to have a UI for this function when there are no input references in it.

If we ever create a merge_expr module with its own server and UI I would recommend keeping the function extracting the merge expression away from the server functions in the spirit of extraditing as much business logic from shiny modules as possible. All the new functions do not need the moduleServer function, so in my mind, it is just bloat and misnomer.

EDIT: also, they return things! which makes this whole thing even more confusing.

@gogonzo

gogonzo commented Jun 23, 2022

Copy link
Copy Markdown
Contributor

I can't imagine why we would like to have a UI for this function when there are no input references in it.
If we ever create a merge_expr module with its own server and UI I would recommend keeping the function extracting the merge expression away from the server functions in the spirit of extraditing as much business logic from shiny modules as possible. All the new functions do not need the moduleServer function, so in my mind, it is just bloat and misnomer.

I don't have a really strong opinion if it should be a module or the function as far as it's reacting to change of the data_extract inputs. If there will ever be request to make a merge_ui (to visually explain how the merge is done) we will have to make it a module (which is not a big deal). I leave the decision to you guys. I'm fine as far as we don't use datasets and preserves the same merge call as predecessor

@mhallal1

Copy link
Copy Markdown
Contributor Author

I can't imagine why we would like to have a UI for this function when there are no input references in it.
If we ever create a merge_expr module with its own server and UI I would recommend keeping the function extracting the merge expression away from the server functions in the spirit of extraditing as much business logic from shiny modules as possible. All the new functions do not need the moduleServer function, so in my mind, it is just bloat and misnomer.

I don't have a really strong opinion if it should be a module or the function as far as it's reacting to change of the data_extract inputs. If there will ever be request to make a merge_ui (to visually explain how the merge is done) we will have to make it a module (which is not a big deal). I leave the decision to you guys. I'm fine as far as we don't use datasets and preserves the same merge call as predecessor

If I remember well, this was a suggestion at some point in the team to visualize the merge process therefore it is staying as a module for now.

Comment thread R/get_dplyr_call.R Resolved
Comment thread R/merge_expression_module.R Resolved
Comment thread R/merge_expression_module.R Resolved
Comment thread R/merge_expression_module.R Resolved
Comment thread R/get_merge_call.R Resolved
@mhallal1 mhallal1 closed this Jun 29, 2022
@cicdguy
cicdguy deleted the 61_data_merge_dependency@main branch June 9, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

data_merge - remove dependency on FilteredData and chunks.

4 participants