Skip to content

Commit

Permalink
Follow changes in nexus
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Oct 23, 2024
1 parent becfb0a commit 961d78a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 60 deletions.
66 changes: 36 additions & 30 deletions R/coda_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,6 @@ coda_plot_ui <- function(id) {
layout_sidebar(
sidebar = sidebar(
width = 400,
checkboxInput(
inputId = ns("order_columns"),
label = "Sort columns",
value = FALSE
),
selectInput(
inputId = ns("order_rows"),
label = "Row order",
choices = NULL,
selected = NULL,
multiple = FALSE,
),
checkboxInput(
inputId = ns("decreasing"),
label = "Decreasing row order",
value = FALSE
),
hr(),
checkboxInput(
inputId = ns("select_major"),
label = "Major elements",
Expand All @@ -46,6 +28,23 @@ coda_plot_ui <- function(id) {
label = "Trace elements",
value = TRUE
),
hr(),
checkboxInput(
inputId = ns("order_columns"),
label = "Sort columns",
value = FALSE
),
selectizeInput(
inputId = ns("order_rows"),
label = "Row order",
choices = NULL, selected = NULL, multiple = FALSE,
options = list(plugins = "remove_button")
),
checkboxInput(
inputId = ns("decreasing"),
label = "Decreasing row order",
value = FALSE
)
), # sidebar
output_plot(
id = ns("plot"),
Expand Down Expand Up @@ -73,19 +72,18 @@ coda_plot_server <- function(id, x) {
stopifnot(is.reactive(x))

moduleServer(id, function(input, output, session) {
## Build barplot -----
bindEvent(
observe({
freezeReactiveValue(input, "order_rows")
choices <- c("", colnames(x()))
updateSelectInput(inputId = "order_rows", choices = choices)
choices <- c("", colnames(data_bar()))
updateSelectizeInput(inputId = "order_rows", choices = choices)
}),
x()
data_bar()
)
plot_bar <- reactive({
req(x())

col <- khroma::color(input$color_qualitative)
## Subset -----
data_bar <- reactive({
req(x())

elements <- logical(ncol(x()))
is_major <- nexus::is_element_major(x())
Expand All @@ -96,15 +94,23 @@ coda_plot_server <- function(id, x) {
elements[which(is_minor)] <- input$select_minor
elements[which(is_trace)] <- input$select_trace

if (!any(elements)) elements <- NULL
if (!any(elements)) return(x())
x()[, elements, drop = FALSE]
})

## Build barplot -----
plot_bar <- reactive({
req(data_bar())

col <- khroma::color(input$color_qualitative)
pal <- khroma::palette_color_discrete(col, domain = colnames(x()))

nexus::barplot(
height = x(),
select = elements,
height = data_bar(),
order_columns = input$order_columns,
order_rows = input$order_rows,
order_rows = get_value(input$order_rows),
decreasing = input$decreasing,
color = khroma::palette_color_discrete(col)
color = pal
)
grDevices::recordPlot()
})
Expand Down
40 changes: 10 additions & 30 deletions R/coda_statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ coda_summary_ui <- function(id) {
gt::gt_output(outputId = ns("mean")),
gt::gt_output(outputId = ns("quantile"))
),
# nav_panel(
# title = "Spread",
# helpText(info_article("Hron & Kubacek", "2011", "10.1007/s00184-010-0299-3")),
# gt::gt_output(outputId = ns("spread")),
# ),
nav_panel(
title = "Covariance",
gt::gt_output(outputId = ns("covariance"))
Expand Down Expand Up @@ -79,11 +74,6 @@ coda_summary_server <- function(id, x) {
stopifnot(is.reactive(x))

moduleServer(id, function(input, output, session) {
## Validate -----
data <- reactive({
x()
})

## Location -----
data_loc <- reactive({
req(x())
Expand All @@ -97,19 +87,7 @@ coda_summary_server <- function(id, x) {
})

## Spread -----
data_spread <- reactive({
req(x())
## Metric variance by group
if (nexus::any_assigned(x())) {
index <- nexus::groups(x())
s <- nexus::aggregate(x(), by = index, FUN = nexus::variance_total)
} else {
m <- nexus::variance_total(x())
s <- matrix(m, nrow = 1, dimnames = list("", NULL))
}
colnames(s) <- c("metric variance")
s
})
# TODO

## Percentiles -----
data_quant <- reactive({
Expand All @@ -118,14 +96,17 @@ coda_summary_server <- function(id, x) {
})

## Histogram -----
observeEvent(x(), {
choices <- colnames(x())
freezeReactiveValue(input, "hist_select")
updateSelectInput(inputId = "hist_select", choices = choices)
})
bindEvent(
observe({
choices <- colnames(x())
freezeReactiveValue(input, "hist_select")
updateSelectInput(inputId = "hist_select", choices = choices)
}),
x()
)
plot_hist <- reactive({
req(x())
nexus::hist(x()[, input$hist_select, drop = FALSE], ncol = 1)
nexus::hist(x(), select = input$hist_select)
grDevices::recordPlot()
})

Expand Down Expand Up @@ -238,7 +219,6 @@ coda_summary_server <- function(id, x) {
## Download -----
output$download <- export_multiple(
location = data_loc,
# spread = data_spread,
quantiles = data_quant,
covariance = data_cov,
variation = data_var,
Expand Down

0 comments on commit 961d78a

Please sign in to comment.