Skip to content

Introducing spiderplot/swimlane/waterfall modules #879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 95 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
12f095c
WIP
gogonzo Nov 5, 2024
d348719
brush_filter to the module
gogonzo Nov 5, 2024
947f151
encapsulate brushing functionality
gogonzo Nov 5, 2024
842ba1b
fix add filter state
gogonzo Nov 5, 2024
a9c9b06
scatterplot + data_table
gogonzo Nov 6, 2024
bf7b4c4
Merge branch 'main' into spotfire_poc2
gogonzo Nov 8, 2024
4b987a6
WIP
gogonzo Nov 15, 2024
089a06a
add data_table module to the app
gogonzo Nov 15, 2024
e0969da
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Nov 15, 2024
c5c744d
remove unneeded
gogonzo Nov 15, 2024
67d4a5c
wip
gogonzo Nov 19, 2024
70d0772
quick fix
gogonzo Nov 19, 2024
2e49a7a
generalise to enable faceting
gogonzo Nov 19, 2024
4038ba8
dummy adam example
gogonzo Nov 19, 2024
06bf0a4
feat: add example using the poc data
vedhav Nov 19, 2024
b9e03c2
WIP plotly
gogonzo Nov 21, 2024
32ee42f
plotly_specs as simple list
gogonzo Nov 21, 2024
4321350
data_table as a brushing table
gogonzo Nov 21, 2024
4137aa1
hide table when not brushed
gogonzo Nov 21, 2024
f1b5d51
feat: allow the user to pass custom colors and symbols
vedhav Nov 21, 2024
780924c
feat: reproduce the osprey example
vedhav Nov 22, 2024
ea559d3
fix: filter using teal.slice and not during data creation
vedhav Nov 22, 2024
21eff43
rename srv_page_data_table to srv_data_table
gogonzo Nov 22, 2024
ea67bd0
feat: add refrence lines + filter unwanted data
vedhav Nov 22, 2024
f913acb
display brushed only
gogonzo Nov 22, 2024
7d5bc89
push local changes
vedhav Nov 28, 2024
179f145
export the custom module for deployment
vedhav Nov 28, 2024
e18dfc3
pass plotly_selected only when it is supported
vedhav Nov 28, 2024
b5884a2
feat: use reactable
vedhav Dec 2, 2024
ef85449
fix: avoid ns clash of layout
vedhav Dec 2, 2024
ef8a5ab
chore: remove local change
vedhav Dec 2, 2024
0fff2a7
feat: use main version of teal and update spiderplot module
vedhav Dec 3, 2024
b8a60c3
feat: update the spiderplot tables + UI enhancements + single parent
vedhav Dec 4, 2024
17e74e3
fix: format the links in two tables
vedhav Dec 4, 2024
d2636fb
feat: add a two module POC for easy maintenance
vedhav Dec 6, 2024
b63249a
Merge branch 'main' into poc3@spotfire_poc2
gogonzo Feb 13, 2025
915ffdf
WIP modules
gogonzo Feb 14, 2025
d028c8e
labels to the data
gogonzo Feb 14, 2025
78e1f2a
fix
gogonzo Feb 14, 2025
2c94370
add reactable module
gogonzo Feb 14, 2025
4f62e13
wip modularize
gogonzo Feb 14, 2025
2065b71
autolabels
gogonzo Feb 14, 2025
7b5ed64
further abstraction
gogonzo Feb 17, 2025
7426193
fixes
gogonzo Feb 17, 2025
c398ee8
swimlane module wip
gogonzo Feb 17, 2025
e68d78f
further changes .adjust_colors
gogonzo Feb 28, 2025
0cd5adc
recent
gogonzo Mar 5, 2025
1596f2d
update the app code
vedhav Mar 5, 2025
bb0917c
WIP waterfall
gogonzo Mar 5, 2025
ef300f5
update
gogonzo Mar 6, 2025
3536699
namespace fix
gogonzo Mar 6, 2025
3eb068a
swimlane with tabs
gogonzo Mar 6, 2025
cfbabc2
poc_onco_v1
gogonzo Mar 6, 2025
bea4996
WIP
gogonzo Mar 11, 2025
2f598c8
Merge branch 'main' into poc3@spotfire_poc2
gogonzo Mar 11, 2025
b496a7e
swimlane fix shapes and fct order
gogonzo Mar 11, 2025
7590be1
wip
gogonzo Mar 12, 2025
cabb695
fix reactables reactivity
gogonzo Mar 12, 2025
29517c8
sort input swimlane
gogonzo Mar 12, 2025
246bfb2
v3
gogonzo Mar 12, 2025
9d51de3
v4
gogonzo Mar 13, 2025
b1e4f60
wip
gogonzo Mar 13, 2025
9c37a22
freeze column
gogonzo Mar 14, 2025
cf14bcf
wip v5
gogonzo Mar 17, 2025
bf0cbad
wip v5
gogonzo Mar 17, 2025
e9ac824
wip v5
gogonzo Mar 17, 2025
165d891
wip v5
gogonzo Mar 18, 2025
607105a
spiderplot lines blue
gogonzo Mar 18, 2025
cb5c616
wip v5
gogonzo Mar 18, 2025
18fd08c
wip v5
gogonzo Mar 18, 2025
02040a5
wip v5
gogonzo Mar 18, 2025
b926f35
wip v5
gogonzo Mar 18, 2025
4495bc7
major cleaning
gogonzo Mar 25, 2025
ae795f8
minor fix
gogonzo Mar 25, 2025
c6e44f5
major cleaning
gogonzo Mar 25, 2025
08465f6
add graphs to the namespace
gogonzo Mar 25, 2025
b6ed653
tm_rmarkdown
gogonzo Mar 28, 2025
a128ff7
tm_rmarkdown
gogonzo Mar 28, 2025
bc1b4ad
tm_rmarkdown
gogonzo Mar 28, 2025
2bbbb96
choices selected
gogonzo Apr 2, 2025
8234f77
update
gogonzo Apr 2, 2025
7a26589
chore: format package
vedhav May 2, 2025
0c2e874
fix: handle color and shape edge cases + rename `event_var` param in …
vedhav May 2, 2025
a065bf5
docs: add examples
vedhav May 2, 2025
589afce
feat: allow the app developer to customize tooltips using column names
vedhav May 5, 2025
4dd1b59
feat: allow custome siize based on a column + expand cards
vedhav May 7, 2025
ce441c3
docs: update roxygen docs for new params
vedhav May 7, 2025
a840f29
feat: add the show selected tooltips module
vedhav May 9, 2025
68d212f
feat: improve the trigger tooltips
vedhav May 14, 2025
8a364bd
fix: remove unused param
vedhav May 14, 2025
4d41676
feat: simplify the trigger tooltip logic
vedhav May 16, 2025
00b5cf8
[skip style] [skip vbump] Restyle files
github-actions[bot] May 16, 2025
723c084
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] May 16, 2025
4126c6b
feat: implement the subject selection for spiider plot
vedhav May 16, 2025
25f7aac
feat: modify the point_size to work like point_colors and point_symbols
vedhav May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Depends:
Imports:
bslib (>= 0.8.0),
checkmate (>= 2.1.0),
colorspace,
colourpicker (>= 1.3.0),
dplyr (>= 1.0.5),
DT (>= 0.13),
Expand All @@ -42,13 +43,20 @@ Imports:
ggpp (>= 0.5.8-1),
ggrepel (>= 0.9.6),
goftest (>= 1.2-3),
graphics,
grDevices,
grid,
gridExtra (>= 2.3),
htmltools,
htmlwidgets (>= 1.6.4),
jsonlite (>= 1.8.9),
lattice (>= 0.18-4),
lifecycle (>= 0.2.0),
MASS (>= 7.3-60),
plotly,
reactable,
rlang (>= 1.0.0),
rmarkdown (>= 2.23),
rtables (>= 0.6.11),
scales (>= 1.3.0),
shinyjs (>= 2.1.0),
Expand All @@ -73,8 +81,6 @@ Suggests:
logger (>= 0.2.0),
nestcolor (>= 0.1.0),
pkgload,
rlang (>= 1.0.0),
rmarkdown (>= 2.23),
roxy.shinylive,
rvest,
shinytest2,
Expand Down
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ S3method(create_sparklines,logical)
S3method(create_sparklines,numeric)
export(add_facet_labels)
export(get_scatterplotmatrix_stats)
export(spiderplotly)
export(swimlanely)
export(tm_a_pca)
export(tm_a_regression)
export(tm_data_table)
Expand All @@ -21,14 +23,21 @@ export(tm_g_distribution)
export(tm_g_response)
export(tm_g_scatterplot)
export(tm_g_scatterplotmatrix)
export(tm_g_spiderplot)
export(tm_g_swimlane)
export(tm_g_waterfall)
export(tm_missing_data)
export(tm_outliers)
export(tm_rmarkdown)
export(tm_t_crosstable)
export(tm_t_reactables)
export(tm_variable_browser)
export(waterfally)
import(ggmosaic)
import(ggplot2)
import(shiny)
import(teal)
import(teal.transform)
importFrom(dplyr,"%>%")
importFrom(lifecycle,deprecated)
importFrom(rlang,":=")
129 changes: 129 additions & 0 deletions R/module_colur_picker.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# todo: to teal widgets?

colour_picker_ui <- function(id) {
ns <- NS(id)
bslib::accordion(
uiOutput(ns("module"), title = "Event colors:", container = bslib::accordion_panel),
open = FALSE
)
}

colour_picker_srv <- function(id, x, default_colors) {
moduleServer(id, function(input, output, session) {
default_colors_adjusted <- reactive({
req(x())
.color_palette_discrete(
levels = unique(x()),
color = default_colors
)
})

color_values <- reactiveVal()
observeEvent(default_colors_adjusted(), {
if (!identical(default_colors_adjusted(), color_values())) {
color_values(default_colors_adjusted())
}
})

output$module <- renderUI({
tagList(
lapply(
names(color_values()),
function(level) {
div(
colourpicker::colourInput(
inputId = session$ns(.name_to_id(level)),
label = level,
value = color_values()[level]
)
)
}
)
)
})

color_input_values <- reactiveVal()
observe({
req(color_values())
new_input_values <- sapply(names(color_values()), function(level) {
c(input[[.name_to_id(level)]], color_values()[[level]])[1]
})
if (!identical(new_input_values, isolate(color_input_values()))) {
isolate(color_input_values(new_input_values))
}
})

color_input_values
})
}



#' Color palette discrete
#'
#' To specify custom discrete colors to `plotly` or `ggplot` elements one needs to specify a vector named by
#' levels of variable used for coloring. This function allows to specify only some or none of the colors/levels
#' as the rest will be filled automatically.
#' @param levels (`character`) values of possible variable levels
#' @param color (`named character`) valid color names (see [colors()]) or hex-colors named by `levels`.
#' @return `character` with hex colors named by `levels`.
.color_palette_discrete <- function(levels, color) {
p <- color[names(color) %in% levels]

if (length(p) > 0) {
p_rgb_num <- grDevices::col2rgb(p)
p_hex <- grDevices::rgb(p_rgb_num[1, ] / 255, p_rgb_num[2, ] / 255, p_rgb_num[3, ] / 255)
p <- stats::setNames(p_hex, names(p))
}

missing_levels <- setdiff(levels, names(p))
N <- length(levels)
n <- length(p)
m <- N - n

if (m > 0 && n > 0) {
all_colors <- colorspace::qualitative_hcl(N)

if (n == 1) {
current_color_hsv <- grDevices::rgb2hsv(grDevices::col2rgb(p))
all_colors_hsv <- grDevices::rgb2hsv(grDevices::col2rgb(all_colors))

distances <- numeric(length(all_colors))
for (i in seq_along(all_colors)) {
h_diff <- min(
abs(current_color_hsv[1] - all_colors_hsv[1, i]),
1 - abs(current_color_hsv[1] - all_colors_hsv[1, i])
)
s_diff <- abs(current_color_hsv[2] - all_colors_hsv[2, i])
v_diff <- abs(current_color_hsv[3] - all_colors_hsv[3, i])
distances[i] <- sqrt(h_diff^2 + s_diff^2 + v_diff^2)
}

idx <- order(distances, decreasing = TRUE)[seq_len(m)]
missing_colors <- all_colors[idx]
} else {
remaining_colors <- all_colors[seq_len(m)]
missing_colors <- remaining_colors
}

p <- c(p, stats::setNames(missing_colors, missing_levels))
} else if (m > 0) {
missing_colors <- colorspace::qualitative_hcl(m)
p <- stats::setNames(missing_colors, missing_levels)
}

result <- p[match(levels, names(p))]
stats::setNames(result, levels)
}


.shape_palette_discrete <- function(levels, symbol) {
if (length(symbol) == 0) {
s <- rep("circle-open", length(levels))
s <- stats::setNames(s, levels)
} else {
s <- stats::setNames(symbol[levels], levels)
s[is.na(s)] <- "circle-open"
}
s
}
10 changes: 10 additions & 0 deletions R/plotly_with_settings.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plotly_with_settings_ui <- function(id, height) {
ns <- NS(id)
plotly::plotlyOutput(ns("plot"), height = height)
}

plotly_with_settings_srv <- function(id, plot) {
moduleServer(id, function(input, output, session) {
output$plot <- plotly::renderPlotly(plot())
})
}
52 changes: 52 additions & 0 deletions R/roxygen2_templates.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,55 @@ roxygen_ggplot2_args_param <- function(...) {
}

# nocov end

#' Shared parameters documentation
#'
#' Defines common arguments shared across multiple functions in the package
#' to avoid repetition by using `inheritParams`.
#'
#' @param plot_height (`numeric`) optional, specifies the plot height as a three-element vector of
#' `value`, `min`, and `max` intended for use with a slider UI element.
#' @param plot_width (`numeric`) optional, specifies the plot width as a three-element vector of
#' `value`, `min`, and `max` for a slider encoding the plot width.
#' @param rotate_xaxis_labels (`logical`) optional, whether to rotate plot X axis labels. Does not
#' rotate by default (`FALSE`).
#' @param ggtheme (`character`) optional, `ggplot2` theme to be used by default. Defaults to `"gray"`.
#' @param ggplot2_args (`ggplot2_args`) object created by [teal.widgets::ggplot2_args()]
#' with settings for the module plot.
#' The argument is merged with options variable `teal.ggplot2_args` and default module setup.
#'
#' For more details see the vignette: `vignette("custom-ggplot2-arguments", package = "teal.widgets")`
#' @param basic_table_args (`basic_table_args`) object created by [teal.widgets::basic_table_args()]
#' with settings for the module table.
#' The argument is merged with options variable `teal.basic_table_args` and default module setup.
#'
#' For more details see the vignette: `vignette("custom-basic-table-arguments", package = "teal.widgets")`
#' @param pre_output (`shiny.tag`) optional, text or UI element to be displayed before the module's output,
#' providing context or a title.
#' with text placed before the output to put the output into context. For example a title.
#' @param post_output (`shiny.tag`) optional, text or UI element to be displayed after the module's output,
#' adding context or further instructions. Elements like `shiny::helpText()` are useful.
#' @param alpha (`integer(1)` or `integer(3)`) optional, specifies point opacity.
#' - When the length of `alpha` is one: the plot points will have a fixed opacity.
#' - When the length of `alpha` is three: the plot points opacity are dynamically adjusted based on
#' vector of `value`, `min`, and `max`.
#' @param size (`integer(1)` or `integer(3)`) optional, specifies point size.
#' - When the length of `size` is one: the plot point sizes will have a fixed size.
#' - When the length of `size` is three: the plot points size are dynamically adjusted based on
#' vector of `value`, `min`, and `max`.
#' @param decorators `r lifecycle::badge("experimental")`
#' (named `list` of lists of `teal_transform_module`) optional,
#' decorator for tables or plots included in the module output reported.
#' The decorators are applied to the respective output objects.
#'
#' @param table_datanames (`character`) names of the datasets which should be listed below the plot
#' when some data points are selected. Objects named after `table_datanames` will be pulled from
#' `data` so it is important that data actually contains these datasets. Please be aware that
#' table datasets must be linked with `plot_dataname` by the relevant [join_keys()].
#' See section "Decorating Module" below for more details.
#'
#' @return Object of class `teal_module` to be used in `teal` applications.
#'
#' @name shared_params
#' @keywords internal
NULL
Loading