Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

443 rcycle@main #637

Merged
merged 40 commits into from
Jun 15, 2022
Merged

443 rcycle@main #637

merged 40 commits into from
Jun 15, 2022

Conversation

Polkas
Copy link
Contributor

@Polkas Polkas commented May 20, 2022

closes #443

Solution with a callable for running the module server and only once when the module tab is first time clicked.

This solves only part of the problem as all of the modules IN SPITE the first one have available all inputs from the 1 line code in the server function.

This is a small code update and we improve the input cycle.
Now each module server function is still called only ONCE nevertheless only when the module TAB is clicked.

The bigger apps like Exploratory should start/initialize much quicker now.
More than that all major apps like Exploratory have a front page module so for them the cycle is healthy now.
When we run the single module alone we still will have an empty first cycle for inputs.

HOW to check that each module is run once, add a print inside the reactive where the callable run is added.

Additionally:
I remove the shinyUI usage which is useless nowadays
Remove a few old comments

Polkas and others added 3 commits May 20, 2022 12:50
@Polkas Polkas marked this pull request as ready for review May 24, 2022 09:21
@github-actions
Copy link
Contributor

github-actions bot commented May 24, 2022

Code Coverage Summary

Filename                         Stmts    Miss  Cover    Missing
-----------------------------  -------  ------  -------  -------------------------------------------
R/default_filter.R                   7       7  0.00%    17-27
R/dummy_functions.R                 78      65  16.67%   12-99
R/example_module.R                  17      17  0.00%    19-35
R/get_rcode_utils.R                 52      11  78.85%   42-51, 94, 99
R/get_rcode.R                      145      99  31.72%   71-74, 85-148, 195, 201-202, 233-284
R/include_css_js.R                  20       0  100.00%
R/init.R                            39      21  46.15%   171, 182-183, 236-257
R/log_app_usage.R                   38      38  0.00%    34-119
R/logging.R                         13      13  0.00%    11-28
R/module_nested_tabs.R              84       4  95.24%   57, 141, 194, 200
R/module_tabs_with_filters.R        52       0  100.00%
R/module_teal_with_splash.R         33       2  93.94%   62, 74
R/module_teal.R                    123      20  83.74%   49, 52, 142-143, 156-162, 168-174, 198, 232
R/modules_debugging.R               19      19  0.00%    41-60
R/modules.R                         82      10  87.80%   208, 268, 371-396
R/reporter_previewer_module.R       12       2  83.33%   18, 22
R/show_rcode_modal.R                20      20  0.00%    17-38
R/utils.R                            6       0  100.00%
R/validations.R                     62      39  37.10%   103-355
R/zzz.R                             11       7  36.36%   3-14
TOTAL                              913     394  56.85%

Results for commit: f14b6728c00056ce08a256ec59e4c94b807c866a

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Contributor

github-actions bot commented May 24, 2022

Unit Tests Summary

    1 files    10 suites   9s ⏱️
  94 tests   94 ✔️ 0 💤 0
198 runs  198 ✔️ 0 💤 0

Results for commit da4f8ed.

♻️ This comment has been updated with latest results.

@Polkas Polkas requested a review from a team May 24, 2022 10:55
@Polkas
Copy link
Contributor Author

Polkas commented May 24, 2022

@gogonzo i applied your recommendation and it still works smooth.

@gogonzo
Copy link
Contributor

gogonzo commented May 25, 2022

This is wonderful. What you basically did is to postpone following

    modules$server_args <- teal.transform::resolve_delayed(modules$server_args, datasets)
    is_module_server <- isTRUE("id" %in% names(formals(modules$server)))
    args <- c(list(id = id, datasets = datasets), modules$server_args)

    if (is_reporter_used(modules)) {
      args <- c(args, list(reporter = reporter))
    }

    if (is_module_server) {
      do.call(modules$server, args)
    } else {
      do.call(callModule, c(args, list(module = modules$server)))
    }

This reactive you created does not have any reactive values - this is good because nothing triggers re-initialization of the module when tab is clicked again. As you said this improves init of the app, but this postponed code-block slows (minimally) when switching the tab.

@Polkas
Copy link
Contributor Author

Polkas commented May 26, 2022

Just to let you know. Since I've approved this PR one thing has changed. Nested tabs are not activated. Screenshot 2022-05-26 at 16 46 44

I'm not sure about this change, which means that it probably needs more discussion after UAT

Thank you for a comment. I just fix this problem. In future please add the code which you use as this will be very helpful.
As I understand @nikolas-burkoff want to test it tomorrow so please give it a chance.

I added a new function ui_nested_tabs_init which has an empty selection and next call old ui_nested_tabs.

Copy link
Contributor

@nikolas-burkoff nikolas-burkoff left a comment

Choose a reason for hiding this comment

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

I guess we will need a NEWS entry but as this isn't going in immediately it's not worth adding yet

R/module_teal.R Show resolved Hide resolved
R/module_nested_tabs.R Outdated Show resolved Hide resolved
R/module_nested_tabs.R Outdated Show resolved Hide resolved
Comment on lines +7 to +31
function wait_for_element(selector) {
return new Promise(resolve => {
let init_check = document.querySelector(selector);
if (init_check) {
return resolve(init_check);
}

const observer = new MutationObserver(() => {
let obs_check = document.querySelector(selector);
if (obs_check) {
resolve(obs_check);
observer.disconnect();
}
});

observer.observe(document.body, {
childList: true,
subtree: true
});
});
}

wait_for_element('div#teal_main_modules_ui').then(() => {
$("div#teal_main_modules_ui a[data-toggle='tab']")[0].click();
});
Copy link
Contributor

@kpagacz kpagacz May 27, 2022

Choose a reason for hiding this comment

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

Suggested change
function wait_for_element(selector) {
return new Promise(resolve => {
let init_check = document.querySelector(selector);
if (init_check) {
return resolve(init_check);
}
const observer = new MutationObserver(() => {
let obs_check = document.querySelector(selector);
if (obs_check) {
resolve(obs_check);
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
wait_for_element('div#teal_main_modules_ui').then(() => {
$("div#teal_main_modules_ui a[data-toggle='tab']")[0].click();
});
const observer = new MutationObserver(() => {
if (document.querySelector("div#teal_main_modules_ui")) {
$("div#teal_main_modules_ui a[data-toggle='tab']")[0].click();
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});

Here is my proposed refactor that keeps the spirit of the original and does away with some of the bloat. I have troubles testing this, but once launched it does click on the first tab. I do not know how to test the business logic properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice update, still I think the current code is more clear as sb know that we are wait_for_element to click sth.
The wait_for_element function could be useful in the future, and it is only 20 lines of code.

If you want to test business logic you should run any of our apps and the shiny input should contains all variables from the first line of any of the executed module server.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is what I did while testing and there was no change between the current state of the pr and my proposed solution when comparing available values of input from a browser put in the first line of the scatterplot module.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you are worried about the readability, then we can change the name of the observer for something meaningful like: tealTabsObserver or if needed a very verbose: clickFirstTealTabWhenAvailable XD

@Polkas Polkas mentioned this pull request May 30, 2022
@Polkas Polkas requested review from kpagacz and gogonzo June 13, 2022 13:27
Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

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

👍

@Polkas Polkas merged commit 8adc87e into main Jun 15, 2022
@Polkas Polkas deleted the 443_rcycle@main branch June 15, 2022 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redundant reactivity cycle on initialization - insertUI
5 participants