Skip to content

Commit

Permalink
update split by group added docu and added better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad1991 committed Nov 12, 2024
1 parent c310124 commit bab0531
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
10 changes: 10 additions & 0 deletions bs/R/MainApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ server <- function(input, output, session) {
size = "l"
))
})
# docu split by group
observeEvent(input[["SG-split_docu"]], {
showModal(modalDialog(
title = "Subsetting the dataset",
includeHTML("www/SplitData.html"),
easyClose = TRUE,
footer = NULL,
size = "l"
))
})

output$conditional_data_ui <- renderUI({
if (Sys.getenv("RUN_MODE") != "SERVER") {
Expand Down
12 changes: 10 additions & 2 deletions bs/R/SplitByGroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ SplitByGroupUI <- function(id) {
),
fluidRow(
div(
actionButton(
NS(id, "split_docu"),
label = NULL,
icon = icon("question-circle")
),
uiOutput(NS(id, "colnames_dropdown")),
class = "boxed-output"
),
Expand Down Expand Up @@ -125,13 +130,16 @@ SplitByGroupServer <- function(id, data) {
e <- try({
selected_cols <- input[[paste0("colnames-dropdown_")]]
selected_groups <- input[[paste0("levels-dropdown_")]]
if (length(selected_groups) == 0 || length(selected_cols) == 0) {
stop("Invalid subset either no columns or now levels of the columns were selected")
}
data$backup_df <- r_vals$df
data$df <- split(r_vals$df, selected_cols, selected_groups)
data$filter_col <- selected_cols
data$filter_group <- selected_groups
})
}, silent = TRUE)
if (inherits(e, "try-error")) {
showNotification("Invalid formula", type = "error")
showNotification(e, type = "error")
}
})
})
Expand Down
1 change: 1 addition & 0 deletions bs/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ split <- function(df, cols, levels) {
}
df_res <- rbind(df_res, df[df[, cols[i]] == levels_temp, ])
}
if (nrow(df) == 0) stop("Subset contains 0 rows")
return(df_res)
}

Expand Down
16 changes: 16 additions & 0 deletions bs/R/www/SplitData.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="boxed-output">
<h4><strong>Split Dataset</strong></h4>
<p>
This modal window enables users to select a subset of their dataset.
The process involves two drop-down menus:
</p>
<ul>
<li><strong>Column Selection:</strong> The first drop-down menu displays the column names from the dataset. Users can select one or more columns for splitting.</li>
<li><strong>Group Selection:</strong> The second drop-down menu presents the unique values (levels) for the selected columns. These values are displayed below each respective column.</li>
</ul>
<p>
By selecting the desired groups, users can filter the dataset accordingly.
Notably, if multiple columns are selected, the data is split sequentially based on the order of the selected columns.
</p>
</div>

0 comments on commit bab0531

Please sign in to comment.