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 named function declarations to onRender() test app #177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions 149-onRender/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
Expand All @@ -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, ");"))
})
}

Expand Down