From 9ef71eb2d6ffff67dd7cd67054754b67edd29cae Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 7 Nov 2019 17:38:30 -0600 Subject: [PATCH 1/2] add named function declarations to onRender() test app --- 149-onRender/app.R | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/149-onRender/app.R b/149-onRender/app.R index b98a6272..f9ed6279 100644 --- a/149-onRender/app.R +++ b/149-onRender/app.R @@ -5,10 +5,13 @@ library(htmlwidgets) ui <- fluidPage( plotlyOutput("p1", height = 200), plotlyOutput("p2", height = 200), - plotlyOutput("p3", height = 200) + plotlyOutput("p3", height = 200), + plotlyOutput("p4", height = 200), + plotlyOutput("p5", height = 200), + plotlyOutput("p6", height = 200) ) -jsCode <- " +no_name <- " function(el) { var ann = { text: 'Test passed!', @@ -20,29 +23,51 @@ function(el) { } " +named <- " +function myFun(el) { + var ann = { + text: 'Test passed!', + x: 0, + y: 0, + showarrow: false + }; + Plotly.relayout(el.id, {annotations: [ann]}); +} +" + server <- function(input, output, session) { p <- plotly_empty() %>% add_annotations( - text = if (packageVersion("htmlwidgets") < "1.4") "Please install htmlwidgets v1.4 or higher and try again" else "Test did not pass :(", + text = if (packageVersion("htmlwidgets") <= "1.5.1") "Please install htmlwidgets v1.4 or higher and try again" else "Test did not pass :(", x = 0, y = 0, showarrow = FALSE - ) + ) %>% + config(displayModeBar = FALSE) - # function declarations work output$p1 <- renderPlotly({ - onRender(p, jsCode) + onRender(p, no_name) }) - # expressions work output$p2 <- renderPlotly({ - onRender(p, paste0("(", jsCode, ")")) + onRender(p, paste0("(", no_name, ")")) }) - # statements work output$p3 <- renderPlotly({ - onRender(p, paste0("(", jsCode, ");")) + onRender(p, paste0("(", no_name, ");")) + }) + + output$p4 <- renderPlotly({ + onRender(p, named) + }) + + output$p5 <- renderPlotly({ + onRender(p, paste0("(", named, ")")) + }) + + output$p6 <- renderPlotly({ + onRender(p, paste0("(", named, ");")) }) } From 2236536781d8e0cd2992d0acd1173a70b979bf22 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 7 Nov 2019 17:44:05 -0600 Subject: [PATCH 2/2] upgrade message --- 149-onRender/app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/149-onRender/app.R b/149-onRender/app.R index f9ed6279..d7b3433a 100644 --- a/149-onRender/app.R +++ b/149-onRender/app.R @@ -39,7 +39,7 @@ server <- function(input, output, session) { p <- plotly_empty() %>% add_annotations( - text = if (packageVersion("htmlwidgets") <= "1.5.1") "Please install htmlwidgets v1.4 or higher and try again" else "Test did not pass :(", + text = if (packageVersion("htmlwidgets") <= "1.5.1") "Please upgrade htmlwidgets" else "Test did not pass :(", x = 0, y = 0, showarrow = FALSE