Skip to content

Commit 32ee42f

Browse files
committed
plotly_specs as simple list
1 parent b9e03c2 commit 32ee42f

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

R/tm_p_swimlane2.r

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ srv_p_swimlane2 <- function(id,
2828
filter_panel_api) {
2929
moduleServer(id, function(input, output, session) {
3030
plotly_q <- reactive({
31+
plotly_call <- .make_plotly_call(specs = plotly_specs)
3132
code <- substitute(
32-
p <- plotly_specs |> plotly::event_register("plotly_selecting"),
33-
list(plotly_specs = plotly_specs)
33+
p <- plotly_call %>% plotly::event_register("plotly_selecting"),
34+
list(plotly_call = plotly_call)
3435
)
3536
eval_code(data(), code = code)
3637
})
@@ -43,3 +44,25 @@ srv_p_swimlane2 <- function(id,
4344
})
4445
})
4546
}
47+
48+
49+
50+
.make_plotly_call <- function(init_call = quote(plotly::plot_ly()), specs) {
51+
points_calls <- lapply(specs, function(x) {
52+
which_fun <- c(which(names(x) == "fun"), 1)[1]
53+
if (is.character(x[[which_fun]])) {
54+
x[[which_fun]] <- str2lang(x[[which_fun]])
55+
}
56+
basic_call <- as.call(
57+
c(
58+
list(x[[which_fun]]),
59+
x[-which_fun]
60+
)
61+
)
62+
})
63+
64+
rhs <- Reduce(
65+
x = c(init_call, points_calls),
66+
f = function(x, y) call("%>%", x, y)
67+
)
68+
}

inst/poc_adam_plotly.r

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ data <- within(teal_data(), {
1919

2020
join_keys(data) <- default_cdisc_join_keys
2121

22-
plotly_specs <- quote(
23-
plotly::plot_ly() |>
24-
plotly::add_bars(x = ~EOSDY, y = ~USUBJID, data = ADSL) |>
25-
plotly::add_markers(x = ~EOSDY, y = ~USUBJID, data = ADSL) |>
26-
plotly::add_markers(x = ~ADY, y = ~USUBJID, data = ADRS)
22+
23+
plotly_specs <- list(
24+
list("plotly::add_bars", x = ~EOSDY, y = ~USUBJID, data = quote(ADSL)),
25+
list("plotly::add_markers", x = ~EOSDY, y = ~USUBJID, color = ~EOTSTT2, data = quote(ADSL)),
26+
list("plotly::add_markers", x = ~ADY, y = ~USUBJID, data = quote(ADRS))
2727
)
2828

29+
2930
app <- init(
3031
data = data,
3132
modules = modules(

0 commit comments

Comments
 (0)