diff --git a/R/tm_p_swimlane2.r b/R/tm_p_swimlane2.r index e426114c5..8757ad4a0 100644 --- a/R/tm_p_swimlane2.r +++ b/R/tm_p_swimlane2.r @@ -28,9 +28,10 @@ srv_p_swimlane2 <- function(id, filter_panel_api) { moduleServer(id, function(input, output, session) { plotly_q <- reactive({ + plotly_call <- .make_plotly_call(specs = plotly_specs) code <- substitute( - p <- plotly_specs |> plotly::event_register("plotly_selecting"), - list(plotly_specs = plotly_specs) + p <- plotly_call %>% plotly::event_register("plotly_selecting"), + list(plotly_call = plotly_call) ) eval_code(data(), code = code) }) @@ -43,3 +44,25 @@ srv_p_swimlane2 <- function(id, }) }) } + + + +.make_plotly_call <- function(init_call = quote(plotly::plot_ly()), specs) { + points_calls <- lapply(specs, function(x) { + which_fun <- c(which(names(x) == "fun"), 1)[1] + if (is.character(x[[which_fun]])) { + x[[which_fun]] <- str2lang(x[[which_fun]]) + } + basic_call <- as.call( + c( + list(x[[which_fun]]), + x[-which_fun] + ) + ) + }) + + rhs <- Reduce( + x = c(init_call, points_calls), + f = function(x, y) call("%>%", x, y) + ) +} diff --git a/inst/poc_adam_plotly.r b/inst/poc_adam_plotly.r index 15889f5af..6b5ef312d 100644 --- a/inst/poc_adam_plotly.r +++ b/inst/poc_adam_plotly.r @@ -19,13 +19,14 @@ data <- within(teal_data(), { join_keys(data) <- default_cdisc_join_keys -plotly_specs <- quote( - plotly::plot_ly() |> - plotly::add_bars(x = ~EOSDY, y = ~USUBJID, data = ADSL) |> - plotly::add_markers(x = ~EOSDY, y = ~USUBJID, data = ADSL) |> - plotly::add_markers(x = ~ADY, y = ~USUBJID, data = ADRS) + +plotly_specs <- list( + list("plotly::add_bars", x = ~EOSDY, y = ~USUBJID, data = quote(ADSL)), + list("plotly::add_markers", x = ~EOSDY, y = ~USUBJID, color = ~EOTSTT2, data = quote(ADSL)), + list("plotly::add_markers", x = ~ADY, y = ~USUBJID, data = quote(ADRS)) ) + app <- init( data = data, modules = modules(