diff --git a/R/tm_p_swimlane2.r b/R/tm_p_swimlane2.r new file mode 100644 index 000000000..e426114c5 --- /dev/null +++ b/R/tm_p_swimlane2.r @@ -0,0 +1,45 @@ +tm_p_swimlane2 <- function(label = "Swimlane Plot Module", plotly_specs, title) { + module( + label = label, + ui = ui_p_swimlane2, + server = srv_p_swimlane2, + datanames = "all", + server_args = list( + plotly_specs = plotly_specs, + title = title + ) + ) +} + + +ui_p_swimlane2 <- function(id) { + ns <- NS(id) + shiny::tagList( + plotly::plotlyOutput(ns("plot")), + verbatimTextOutput(ns("selecting")), + shinyjs::hidden(tableOutput(ns("table"))) + ) +} + +srv_p_swimlane2 <- function(id, + data, + plotly_specs, + title = "Swimlane plot", + filter_panel_api) { + moduleServer(id, function(input, output, session) { + plotly_q <- reactive({ + code <- substitute( + p <- plotly_specs |> plotly::event_register("plotly_selecting"), + list(plotly_specs = plotly_specs) + ) + eval_code(data(), code = code) + }) + + output$plot <- plotly::renderPlotly(plotly_q()$p) + + output$selecting <- renderPrint({ + d <- plotly::event_data("plotly_selecting") + if (is.null(d)) "Brush points appear here (double-click to clear)" else d + }) + }) +} diff --git a/inst/poc_adam_plotly.r b/inst/poc_adam_plotly.r new file mode 100644 index 000000000..15889f5af --- /dev/null +++ b/inst/poc_adam_plotly.r @@ -0,0 +1,41 @@ +pkgload::load_all("teal") +pkgload::load_all("teal.widgets") +pkgload::load_all("teal.modules.general") + +# Example data +data <- within(teal_data(), { + library(dplyr) + library(tidyr) + ADSL <- teal.data::rADSL |> mutate( + EOTSTT2 = case_when( + !is.na(DCSREAS) ~ DCSREAS, + TRUE ~ EOTSTT + ) + ) + + ADAE <- teal.data::rADAE + ADRS <- teal.data::rADRS +}) + +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) +) + +app <- init( + data = data, + modules = modules( + tm_data_table(), + tm_p_swimlane2( + label = "Swimlane", + plotly_specs = plotly_specs, + title = "Swimlane Efficacy Plot" + ) + ) +) + +shinyApp(app$ui, app$server)