-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
[Bug]: qenv prints plots to the device when running shiny app #84
Closed
Tracked by
#2
gogonzo opened this issue
Oct 28, 2022
· 2 comments
· Fixed by #124 or insightsengineering/teal.modules.general#540
Closed
Tracked by
#2
[Bug]: qenv prints plots to the device when running shiny app #84
gogonzo opened this issue
Oct 28, 2022
· 2 comments
· Fixed by #124 or insightsengineering/teal.modules.general#540
Comments
21 tasks
Maybe some sort of dev.off in verbatim_popup would make a trick. |
Acceptance Criteria
|
3 tasks
kartikeyakirar
added a commit
that referenced
this issue
Jul 31, 2023
this fixes #84 related PR insightsengineering/teal.modules.general#540 To prevent the IDE from displaying plots when using the eval_code() method containing any graphic element, I utilized dev.new() before and dev.off() after the eval_code() method definition. This approach opens and closes the graphic device, effectively suppressing the plot outputs. Now Before ✔️ ✔️ "plot+observe" caused by observe (does not disply on ide) ✔️ ❌ "pws+warn" caused by disable in verbatim_popup_srv ✔️ ❌ "pws+tws" caused by table_with_settings ✔️ ❌ "tmg-scatterplot" caused by verbatim_popup_srv and renderDataTable Sample code to test: ``` library(shiny) library(ggplot2) library(magrittr) library(rtables) pkgload::load_all("teal.widgets") pkgload::load_all("teal.modules.general") pkgload::load_all("teal.code") library(teal) library(scda) ADSL <- synthetic_cdisc_data("latest")$adsl ui_plot_noqenv <- function(id) { ns <- NS(id) fluidPage( shinyjs::useShinyjs(), div( plotOutput(ns("plot_normal")), DT::dataTableOutput(ns("tab2")) ) ) } server_plot_noqenv <- function(id, data) { moduleServer(id, function(input, output, session) { q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('basic') plot(1:10) print(p) })) }) output$plot_normal <- renderPlot(q2()[["p"]]) output$tab2 <- DT::renderDataTable({ q2() head(iris) }) }) } ui_plot <- function(id) { ns <- NS(id) fluidPage( shinyjs::useShinyjs(), fluidRow( column(9, plotOutput(ns("plot_normal"))), column(3, verbatim_popup_ui(ns("pop2"), "SRC")) ) ) } server_plot <- function(id, data) { moduleServer(id, function(input, output, session) { q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('plot') plot(1:10) print(p) })) }) output$plot_normal <- renderPlot(q2()[["p"]]) verbatim_popup_srv("pop2", reactive(paste(get_code(q2()), collapse = "\n")), "SRC") }) } ui_plot_and_table <- function(id) { ns <- NS(id) fluidPage( shinyjs::useShinyjs(), fluidRow( column(9, plotOutput(ns("plot_normal"))), column(3, verbatim_popup_ui(ns("pop2"), "SRC")) ), DT::dataTableOutput(ns("table")) ) } server_plot_and_table <- function(id, data) { moduleServer(id, function(input, output, session) { q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('plot+table') plot(1:10) print(p) })) }) output$plot_normal <- renderPlot(q2()[["p"]]) output$table <- DT::renderDataTable(q2()[["iris"]]) verbatim_popup_srv("pop2", reactive(paste(get_code(q2()), collapse = "\n")), "SRC") }) } ui_plot_and_observe <- function(id) { ns <- NS(id) fluidPage( shinyjs::useShinyjs(), fluidRow( column(9, plotOutput(ns("plot_normal"))), column(3, verbatim_popup_ui(ns("pop2"), "SRC")) ) ) } server_plot_and_observe <- function(id, data) { moduleServer(id, function(input, output, session) { q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('plot+observe') plot(1:10) print(p) })) }) output$plot_normal <- renderPlot(q2()[["p"]]) observe(q2()) verbatim_popup_srv("pop2", reactive(paste(get_code(q2()), collapse = "\n")), "SRC") }) } ui_plot_uirender <- function(id) { ns <- NS(id) fluidPage( shinyjs::useShinyjs(), uiOutput(ns("ui")) ) } server_plot_uirender <- function(id, data) { moduleServer(id, function(input, output, session) { output$ui <- renderUI({ fluidRow( column(9, plotOutput(session$ns("plot_normal"))), column(3, verbatim_popup_ui(session$ns("pop2"), "SRC")) ) }) q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('plot+uirender') plot(1:10) print(p) })) }) output$plot_normal <- renderPlot(q2()[["p"]]) verbatim_popup_srv("pop2", reactive(paste(get_code(q2()), collapse = "\n")), "SRC") }) } ui_pws <- function(id) { ns <- NS(id) fluidPage( shinyjs::useShinyjs(), fluidRow( column(9, teal.widgets::plot_with_settings_ui(id = ns("p2"))), column(3, verbatim_popup_ui(ns("pop2"), "SRC")) ) ) } server_pws <- function(id, data) { moduleServer(id, function(input, output, session) { q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('pws') plot(1:10) print(p) })) }) teal.widgets::plot_with_settings_srv(id = "p2", plot_r = reactive(q2()[["p"]])) verbatim_popup_srv("pop2", reactive(paste(get_code(q2()), collapse = "\n")), "SRC") }) } ui_pws_and_warn <- function(id) { ns <- NS(id) fluidPage( shinyjs::useShinyjs(), fluidRow( column(9, teal.widgets::plot_with_settings_ui(id = ns("p2"))), column(3, verbatim_popup_ui(ns("pop2"), "SRC")), column(3, verbatim_popup_ui(ns("pop2w"), "Warn")) ) ) } server_pws_and_warn <- function(id) { moduleServer(id, function(input, output, session) { q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('pws+warn') plot(1:10) print(p) })) }) teal.widgets::plot_with_settings_srv(id = "p2", plot_r = reactive(q2()[["p"]])) verbatim_popup_srv("pop2", reactive(paste(get_code(q2()), collapse = "\n")), "SRC") verbatim_popup_srv("pop2w", reactive(get_warnings(q2())), "Warn", disabled = reactive(is.null(get_warnings(q2())))) }) } ui_pws_tws <- function(id) { ns <- NS(id) fluidPage( shinyjs::useShinyjs(), fluidRow( column(9, teal.widgets::plot_with_settings_ui(id = ns("p2"))), column(3, verbatim_popup_ui(ns("pop2"), "SRC")) ), teal.widgets::table_with_settings_ui(id = ns("t2")) ) } server_pws_tws <- function(id) { moduleServer(id, function(input, output, session) { q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('pws+tws') plot(1:10) print(p) })) }) table_r <- reactive({ q2() l <- basic_table() %>% split_cols_by("ARM") %>% analyze(c("SEX", "AGE")) build_table(l, DM) }) teal.widgets::plot_with_settings_srv(id = "p2", plot_r = reactive(q2()[["p"]])) teal.widgets::table_with_settings_srv(id = "t2", table_r = reactive(table_r())) verbatim_popup_srv("pop2", reactive(paste(get_code(q2()), collapse = "\n")), "SRC") }) } server_pws_tws_fix <- function(id) { moduleServer(id, function(input, output, session) { q2 <- reactive({ new_qenv() |> eval_code(quote({ iris[1:10, "Sepal.Width"] <- NA p <- ggplot(data = iris) + geom_point(aes(x = Sepal.Width, y = Petal.Width)) + ggtitle('pws+tws') plot(1:10) print(p) })) }) table_r <- reactive({ pdf(NULL) q2() dev.off() l <- basic_table() %>% split_cols_by("ARM") %>% analyze(c("SEX", "AGE")) build_table(l, DM) }) teal.widgets::plot_with_settings_srv(id = "p2", plot_r = reactive(q2()[["p"]])) teal.widgets::table_with_settings_srv(id = "t2", table_r = reactive(table_r())) verbatim_popup_srv("pop2", reactive(paste(get_code(q2()), collapse = "\n")), "SRC") }) } app <- teal::init( data = list(iris = iris, ADSL = ADSL), modules = list( module("basic", ui = ui_plot_noqenv, server = server_plot_noqenv), module("plot", ui = ui_plot, server = server_plot), module("plot+table", ui = ui_plot_and_table, server = server_plot_and_table), # module("plot+observe", ui = ui_plot_and_observe, server = server_plot_and_observe), # extra print by observe module("generic+renderUI", ui = ui_plot_uirender, server = server_plot_uirender), module("pws+warn", ui = ui_pws_and_warn, server = server_pws_and_warn), # extra print by verbatim_poppup module("pws", ui = ui_pws, server = server_pws), module("pws+tws", ui = ui_pws_tws, server = server_pws_tws), # extra print by tws module("pws+tws+fix", ui = ui_pws_tws, server = server_pws_tws_fix), tm_g_scatterplot( # extra print by multiple things label = "Scatterplot Choices", x = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2")), selected = "AGE", multiple = FALSE, fixed = FALSE ) ), y = data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(ADSL, c("AGE", "BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE ) ) ) ) ) runApp(app) ``` --------- Signed-off-by: kartikeya kirar <kirar.kartikeya1@gmail.com> Co-authored-by: kartikeya <kartikeya.kirar@unicle.life> Co-authored-by: go_gonzo <dawid.kaledkowski@gmail.com> Co-authored-by: Dawid Kałędkowski <6959016+gogonzo@users.noreply.github.com> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
kartikeyakirar
added a commit
to insightsengineering/teal.modules.general
that referenced
this issue
Jul 31, 2023
this fixes insightsengineering/teal.code#84 --------- Co-authored-by: go_gonzo <dawid.kaledkowski@gmail.com> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: kartikeya <kartikeya.kirar@unicle.life>
This was referenced Jul 31, 2023
qenv prints plots to the device when running shiny app
insightsengineering/teal.modules.clinical#799
Closed
kartikeyakirar
added a commit
to insightsengineering/teal.modules.clinical
that referenced
this issue
Aug 4, 2023
this PR fixes #799 and PR is related to issue insightsengineering/teal.code#84 ====================================================== based on this PR insightsengineering/teal.modules.general#553 teal.code::dev_suppress() is used to avoid printing plot on console. --------- Co-authored-by: kartikeya <kartikeya.kirar@unicle.life>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
In
qenv
we executeprint(plot)
to capture possible errors or warning during print of the plot. In the same time thisplot
is sent to theshiny::plotOutput
(through teal.widgets::plot_with_settings). Issue is following - plot is printed in thereactive
and the same reactive is used inplot_with_settings_srv
, inverbatim_popup_srv
(SRC and warnings) and sometimes intable_with_settings
.This results in a situation that during interactive session plot output is rendered in shiny and additionally printed to the device - this is annoying as it's printed to IDE. I'm not also sure if:
Please analyse example below and observe when output is printed to IDE. Currently, we experience additional print in following modules:
"plot+observe"
caused by observe - expected"pws+warn"
caused by disable in verbatim_popup_srv (not expected)"pws+tws"
caused by table_with_settings (not expected)"tmg-scatterplot"
caused by verbatim_popup_srv and renderDataTable (not expected)Run the example and see
The text was updated successfully, but these errors were encountered: