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

add reporter #635

Merged
merged 28 commits into from
May 23, 2022
Merged

add reporter #635

merged 28 commits into from
May 23, 2022

Conversation

nikolas-burkoff
Copy link
Contributor

@nikolas-burkoff nikolas-burkoff commented May 18, 2022

Closes insightsengineering/teal.reporter#5 also uses insightsengineering/teal.reporter#47 and a PR for rtables here insightsengineering/rtables#328

See also https://github.com/insightsengineering/idr-tasks/issues/301

image

library(teal)
library(teal.reporter)

example_reporter_module <- function(label = "Example") {
    module(
        label,
        server = function(id, datasets, reporter) {
            moduleServer(id, function(input, output, session) {
                output$text <- renderPrint(datasets$get_data(input$dataname, filtered = TRUE))
                
                ### REPORTER
                card_fun <- function(card = ReportCard$new(), comment) {
                    card$set_name("Table Module")
                    card$append_text(paste("Selected dataset", input$dataname), "header2")
                    card$append_text("Selected Filters", "header2")
                    card$append_text(datasets$get_formatted_filter_state())
                    card$append_text("Module Table", "header2")
                    card$append_table(datasets$get_data(input$dataname, filtered = TRUE))
                    if (!comment == "") {
                        card$append_text("Comment", "header3")
                        card$append_text(comment)
                    }
                    card
                }
                
                teal.reporter::add_card_button_srv("addReportCard", reporter = reporter, card_fun = card_fun)
                teal.reporter::download_report_button_srv("downloadButton", reporter = reporter)
                teal.reporter::reset_report_button_srv("resetButton", reporter)
                ###
            })
        },
        ui = function(id, datasets) {
            ns <- NS(id)
            teal.widgets::standard_layout(
                output = verbatimTextOutput(ns("text")),
                encoding = tagList(
                    div(
                        teal.reporter::add_card_button_ui(ns("addReportCard")),
                        teal.reporter::download_report_button_ui(ns("downloadButton")),
                        teal.reporter::reset_report_button_ui(ns("resetButton"))
                    ),
                    selectInput(ns("dataname"), "Choose a dataset", choices = datasets$datanames()),
                )
            )
        },
        filters = "all"
    )
}


app <- init(
    data = teal_data(dataset("IRIS", iris), check = FALSE),
    modules = modules(
        example_module(),
        example_reporter_module()
    ),
    header = "Example teal app with reporter"
)

shinyApp(app$ui, app$server)

@Polkas
Copy link
Contributor

Polkas commented May 18, 2022

Fantastic job, everything is ok.

We only have to remove " reporter <- teal.reporter::Reporter$new()" from example app, your first comment.
I already remove it.

@nikolas-burkoff
Copy link
Contributor Author

@kpagacz

If we have filters we see this:
image

If we don't we see this:
image

Should we update the formatting function in teal.slice to say No filters or remove IRIS etc? And we can't do append_text(cat(datasets$get_formatted_filter_state()) as that outputs to console and we get an app crash as we have a NULL in append_text.

Feel free to spin out to another issue or ignore

R/modules.R Outdated Show resolved Hide resolved
@Polkas Polkas self-assigned this May 19, 2022
reporter <- teal.reporter::Reporter$new()

if (use_reporter(modules)) {
modules <- append_module(modules, reporter_previewer_module())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be done before ui_tabs_with_filters (~ 20 lines below) so that the previewer ui is appended before being called

@Polkas
Copy link
Contributor

Polkas commented May 19, 2022

One think to check here insightsengineering/teal.reporter#48 (comment)

"Does the reporter instance unique for each user on the deployed app."

@nikolas-burkoff
Copy link
Contributor Author

nikolas-burkoff commented May 19, 2022

"Does the reporter instance unique for each user on the deployed app."

It seems to be unique per shiny session - but def worth checking

@nikolas-burkoff nikolas-burkoff marked this pull request as ready for review May 19, 2022 09:45
@github-actions
Copy link
Contributor

github-actions bot commented May 19, 2022

Code Coverage Summary

Filename                         Stmts    Miss  Cover    Missing
-----------------------------  -------  ------  -------  -------------------------------------------
R/default_filter.R                   7       7  0.00%    17-27
R/dummy_functions.R                 89      66  25.84%   12-99, 116
R/example_module.R                  17      17  0.00%    18-34
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              76       4  94.74%   53, 133, 184, 190
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                    122      20  83.61%   49, 52, 144-145, 158-164, 170-176, 200, 230
R/modules_debugging.R               19      19  0.00%    41-60
R/modules.R                         80       9  88.75%   208, 372-397
R/reporter_previewer_module.R       12       2  83.33%   17, 21
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: d2b772dd9ad0551b343b5e787f4d41872fc3c939

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Contributor

github-actions bot commented May 19, 2022

Unit Tests Summary

    1 files    10 suites   11s ⏱️
  91 tests   91 ✔️ 0 💤 0
196 runs  196 ✔️ 0 💤 0

Results for commit 13fc537.

♻️ This comment has been updated with latest results.

R/module_nested_tabs.R Outdated Show resolved Hide resolved
R/modules.R Outdated Show resolved Hide resolved
checkmate::assert_class(module, "teal_module")
modules$children <- c(modules$children, list(module))
labels <- vapply(modules$children, function(submodule) submodule$label, character(1))
names(modules$children) <- make.unique(gsub("[^[:alnum:]]", "_", tolower(labels)), sep = "_")
Copy link
Contributor

Choose a reason for hiding this comment

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

In what capacity are the names of the modules used in teal?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you plan on testing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My suspicion is it is to do with knowing which module is active so that a signal can be sent to the filter panel when they change. @gogonzo ?

Do you plan on testing this?

Erm, This is copied from the modules function we'll see

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test written let me know if you want more

server_fun <- function(id, datasets) {
}

ui_fun <- function(id, ...) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is defined a few times.
Please define it once at the top

Comment on lines +705 to +708
mod <- create_mod(label = "a")
mod2 <- create_mod(label = "c")
mods <- modules(label = "c", mod, mod2)
mod3 <- create_mod(label = "c")
Copy link
Contributor

Choose a reason for hiding this comment

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

please define once reused variables.

Copy link
Contributor Author

@nikolas-burkoff nikolas-burkoff May 23, 2022

Choose a reason for hiding this comment

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

have discussed with M, keeping this as is to keep tests independent

vignettes/teal.Rmd Outdated Show resolved Hide resolved
Nikolas Burkoff and others added 7 commits May 23, 2022 08:44
Co-authored-by: Maciej Nasinski <[email protected]>
Co-authored-by: Maciej Nasinski <[email protected]>
Co-authored-by: Mahmoud Hallal <[email protected]>
Co-authored-by: Maciej Nasinski <[email protected]>
@mhallal1
Copy link
Collaborator

mhallal1 commented May 23, 2022

Screenshot from 2022-05-23 10-05-55
Screenshot from 2022-05-23 10-05-40
I am not sure this issue belongs to this PR but I do not like how the buttons of reporter or previewer look like on my laptop, they look great on a bigger screen.

@Polkas
Copy link
Contributor

Polkas commented May 23, 2022

@mhallal1 I already update the example app to use regular div not a fluidRow.

Nikolas Burkoff added 2 commits May 23, 2022 09:09
@kpagacz
Copy link
Contributor

kpagacz commented May 23, 2022

Regarding the styling - I have opened another issue to style SimpleReporter better and assigned it to myself. Hopefully, I can figure out something nice. insightsengineering/teal.reporter#50

I don't think I am touching individual buttons.

Nikolas Burkoff added 2 commits May 23, 2022 09:16
Copy link
Contributor

@Polkas Polkas left a comment

Choose a reason for hiding this comment

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

GREAT JOB

image

As we talked, we have to wait for the rtables update now.

@nikolas-burkoff nikolas-burkoff merged commit dadec89 into main May 23, 2022
@nikolas-burkoff nikolas-burkoff deleted the 5_reporter_in_teal@main branch May 23, 2022 14:39
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.

Implement reporter buttons and simple previewer inside "simple shiny"/NEST App
5 participants