Skip to content

Commit

Permalink
plotly_specs as simple list
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Nov 21, 2024
1 parent b9e03c2 commit 32ee42f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
27 changes: 25 additions & 2 deletions R/tm_p_swimlane2.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
)
}
11 changes: 6 additions & 5 deletions inst/poc_adam_plotly.r
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 32ee42f

Please sign in to comment.