diff --git a/149-onRender/app.R b/149-onRender/app.R index b98a6272..d7b3433a 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 upgrade htmlwidgets" 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, ");")) }) }