Skip to content

Commit

Permalink
WIP plotly
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Nov 21, 2024
1 parent 06bf0a4 commit b9e03c2
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
45 changes: 45 additions & 0 deletions R/tm_p_swimlane2.r
Original file line number Diff line number Diff line change
@@ -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
})
})
}
41 changes: 41 additions & 0 deletions inst/poc_adam_plotly.r
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b9e03c2

Please sign in to comment.