mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2026-06-19 04:27:30 +02:00
revised ui
This commit is contained in:
parent
b2745f5628
commit
af4e21b836
22 changed files with 110 additions and 64 deletions
|
|
@ -1 +1 @@
|
|||
app_version <- function()'26.4.1'
|
||||
app_version <- function()'26.4.2'
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ create_column_ui <- function(id) {
|
|||
actionButton(
|
||||
inputId = ns("compute"),
|
||||
label = tagList(
|
||||
phosphoricons::ph("pencil"), i18n$t("Create column")
|
||||
phosphoricons::ph("pencil",weight = "bold"), i18n$t("Create column")
|
||||
),
|
||||
class = "btn-outline-primary",
|
||||
width = "100%"
|
||||
|
|
@ -84,7 +84,7 @@ create_column_ui <- function(id) {
|
|||
actionButton(
|
||||
inputId = ns("remove"),
|
||||
label = tagList(
|
||||
phosphoricons::ph("x-circle"),
|
||||
phosphoricons::ph("x-circle",weight = "bold"),
|
||||
i18n$t("Cancel")
|
||||
),
|
||||
class = "btn-outline-danger",
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ cut_variable_ui <- function(id) {
|
|||
toastui::datagridOutput2(outputId = ns("count")),
|
||||
actionButton(
|
||||
inputId = ns("create"),
|
||||
label = tagList(phosphoricons::ph("scissors"), i18n$t("Create factor variable")),
|
||||
label = tagList(phosphoricons::ph("scissors",weight = "bold"), i18n$t("Create factor variable")),
|
||||
class = "btn-outline-primary float-end"
|
||||
),
|
||||
tags$div(class = "clearfix")
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
hosted_version <- function()'v26.4.1-260402'
|
||||
hosted_version <- function()'v26.4.2-260410'
|
||||
|
|
|
|||
|
|
@ -714,7 +714,7 @@ make_success_alert <- function(data,
|
|||
i18n$t("Data ready to be imported!")
|
||||
),
|
||||
sprintf(
|
||||
i18n$t("Data has %s obs. of %s variables."),
|
||||
i18n$t("The data set has %s obs. in %s variables."),
|
||||
nrow(data),
|
||||
ncol(data)
|
||||
),
|
||||
|
|
@ -725,7 +725,7 @@ make_success_alert <- function(data,
|
|||
i18n$t("Data successfully imported!")
|
||||
),
|
||||
sprintf(
|
||||
i18n$t("Data has %s obs. of %s variables."),
|
||||
i18n$t("The data set has %s obs. in %s variables."),
|
||||
nrow(data),
|
||||
ncol(data)
|
||||
),
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ data_missings_ui <- function(id, ...) {
|
|||
inputId = ns("act_miss"),
|
||||
label = i18n$t("Evaluate"),
|
||||
width = "100%",
|
||||
icon = phosphoricons::ph("calculator"),
|
||||
icon = phosphoricons::ph("calculator",weight = "bold"),
|
||||
# icon = shiny::icon("calculator"),
|
||||
disabled = TRUE
|
||||
)
|
||||
|
|
|
|||
90
R/plot_bar.R
90
R/plot_bar.R
|
|
@ -1,5 +1,29 @@
|
|||
plot_bar <- function(data, pri, sec, ter = NULL, style = c("stack", "dodge", "fill"),
|
||||
color.palette = "viridis", max_level = 30, ...) {
|
||||
#' Title
|
||||
#'
|
||||
#' @name data-plots
|
||||
#'
|
||||
#' @param style barplot style passed to geom_bar position argument.
|
||||
#' One of c("stack", "dodge", "fill")
|
||||
#'
|
||||
#' @returns ggplot list object
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' mtcars |>
|
||||
#' dplyr::mutate(cyl = factor(cyl), am = factor(am)) |>
|
||||
#' plot_bar(pri = "cyl", sec = "am", style = "fill")
|
||||
#'
|
||||
#' mtcars |>
|
||||
#' dplyr::mutate(dplyr::across(tidyselect::all_of(c("cyl","am","gear")),factor)) |>
|
||||
#' plot_bar(pri = "cyl", sec = "gear", ter = "am", style = "stack",color.palette="turbo")
|
||||
plot_bar <- function(data,
|
||||
pri,
|
||||
sec = NULL,
|
||||
ter = NULL,
|
||||
style = c("stack", "dodge", "fill"),
|
||||
color.palette = "viridis",
|
||||
max_level = 30,
|
||||
...) {
|
||||
style <- match.arg(style)
|
||||
|
||||
if (!is.null(ter)) {
|
||||
|
|
@ -8,7 +32,7 @@ plot_bar <- function(data, pri, sec, ter = NULL, style = c("stack", "dodge", "fi
|
|||
ds <- list(data)
|
||||
}
|
||||
|
||||
out <- lapply(ds, \(.ds){
|
||||
out <- lapply(ds, \(.ds) {
|
||||
plot_bar_single(
|
||||
data = .ds,
|
||||
pri = pri,
|
||||
|
|
@ -19,7 +43,10 @@ plot_bar <- function(data, pri, sec, ter = NULL, style = c("stack", "dodge", "fi
|
|||
)
|
||||
})
|
||||
|
||||
wrap_plot_list(out, title = glue::glue(i18n$t("Grouped by {get_label(data,ter)}")), ...)
|
||||
wrap_plot_list(out,
|
||||
title = glue::glue(i18n$t("Grouped by {get_label(data,ter)}")),
|
||||
y.axis.percentage = TRUE,
|
||||
...)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -41,7 +68,11 @@ plot_bar <- function(data, pri, sec, ter = NULL, style = c("stack", "dodge", "fi
|
|||
#' mtcars |>
|
||||
#' dplyr::mutate(cyl = factor(cyl), am = factor(am)) |>
|
||||
#' plot_bar_single(pri = "cyl", style = "stack",color.palette="turbo")
|
||||
plot_bar_single <- function(data, pri, sec = NULL, style = c("stack", "dodge", "fill"), max_level = 30,
|
||||
plot_bar_single <- function(data,
|
||||
pri,
|
||||
sec = NULL,
|
||||
style = c("stack", "dodge", "fill"),
|
||||
max_level = 30,
|
||||
color.palette = "viridis") {
|
||||
style <- match.arg(style)
|
||||
|
||||
|
|
@ -51,16 +82,11 @@ plot_bar_single <- function(data, pri, sec = NULL, style = c("stack", "dodge", "
|
|||
|
||||
p_data <- as.data.frame(table(data[c(pri, sec)])) |>
|
||||
dplyr::mutate(dplyr::across(tidyselect::any_of(c(pri, sec)), forcats::as_factor),
|
||||
p = Freq / NROW(data)
|
||||
)
|
||||
p = Freq / NROW(data))
|
||||
|
||||
|
||||
if (nrow(p_data) > max_level) {
|
||||
p_data <- sort_by(
|
||||
p_data,
|
||||
p_data[["Freq"]],
|
||||
decreasing = TRUE
|
||||
) |>
|
||||
p_data <- sort_by(p_data, p_data[["Freq"]], decreasing = TRUE) |>
|
||||
head(max_level)
|
||||
}
|
||||
|
||||
|
|
@ -73,39 +99,31 @@ plot_bar_single <- function(data, pri, sec = NULL, style = c("stack", "dodge", "
|
|||
fill <- pri
|
||||
}
|
||||
|
||||
p <- ggplot2::ggplot(
|
||||
p_data,
|
||||
ggplot2::aes(
|
||||
x = .data[[pri]],
|
||||
y = p,
|
||||
fill = .data[[fill]]
|
||||
)
|
||||
) +
|
||||
p <- ggplot2::ggplot(p_data, ggplot2::aes(x = .data[[pri]], y = p, fill = .data[[fill]])) +
|
||||
ggplot2::geom_bar(position = style, stat = "identity") +
|
||||
ggplot2::scale_y_continuous(labels = scales::percent) +
|
||||
scale_fill_generate(palette=color.palette) +
|
||||
ggplot2::ylab("Percentage") +
|
||||
ggplot2::xlab(get_label(data,pri))+
|
||||
ggplot2::guides(fill = ggplot2::guide_legend(title = get_label(data,fill)))
|
||||
scale_fill_generate(palette = color.palette) +
|
||||
ggplot2::xlab(get_label(data, pri)) +
|
||||
ggplot2::guides(fill = ggplot2::guide_legend(title = get_label(data, fill)))
|
||||
|
||||
## To handle large number of levels and long level names
|
||||
|
||||
if (nrow(p_data) > 10 | any(nchar(as.character(p_data[[pri]])) > 6)) {
|
||||
if (nrow(p_data) > 10 |
|
||||
any(nchar(as.character(p_data[[pri]])) > 6)) {
|
||||
p <- p +
|
||||
# ggplot2::guides(fill = "none") +
|
||||
ggplot2::theme(
|
||||
axis.text.x = ggplot2::element_text(
|
||||
angle = 90,
|
||||
vjust = 1, hjust = 1
|
||||
))+
|
||||
ggplot2::theme(
|
||||
axis.text.x = ggplot2::element_text(vjust = 0.5)
|
||||
)
|
||||
ggplot2::theme(axis.text.x = ggplot2::element_text(
|
||||
angle = 90,
|
||||
vjust = 1,
|
||||
hjust = 1
|
||||
)) +
|
||||
ggplot2::theme(axis.text.x = ggplot2::element_text(vjust = 0.5))
|
||||
|
||||
if (is.null(sec)){
|
||||
if (is.null(sec)) {
|
||||
p <- p +
|
||||
ggplot2::guides(fill = "none")
|
||||
}
|
||||
}
|
||||
p
|
||||
p +
|
||||
ggplot2::scale_y_continuous(labels = scales::percent) +
|
||||
ggplot2::ylab("Percentage")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ string_split_ui <- function(id) {
|
|||
),
|
||||
actionButton(
|
||||
inputId = ns("create"),
|
||||
label = tagList(phosphoricons::ph("pencil"), i18n$t("Apply split")),
|
||||
label = tagList(phosphoricons::ph("pencil",weight = "bold"), i18n$t("Apply split")),
|
||||
class = "btn-outline-primary float-end"
|
||||
),
|
||||
tags$div(class = "clearfix")
|
||||
|
|
|
|||
BIN
R/sysdata.rda
BIN
R/sysdata.rda
Binary file not shown.
|
|
@ -124,7 +124,7 @@ ui_elements <- function(selection) {
|
|||
inputId = "modal_initial_view",
|
||||
label = i18n$t("Quick overview"),
|
||||
width = "100%",
|
||||
icon = phosphoricons::ph("binoculars"),
|
||||
icon = phosphoricons::ph("binoculars",weight = "bold"),
|
||||
# icon = shiny::icon("binoculars"),
|
||||
disabled = FALSE
|
||||
),
|
||||
|
|
@ -169,7 +169,7 @@ ui_elements <- function(selection) {
|
|||
inputId = "act_start",
|
||||
label = i18n$t("Let's begin!"),
|
||||
width = "100%",
|
||||
icon = phosphoricons::ph("play"),
|
||||
icon = phosphoricons::ph("play",weight = "bold"),
|
||||
# icon = shiny::icon("play"),
|
||||
disabled = TRUE
|
||||
),
|
||||
|
|
@ -460,7 +460,7 @@ ui_elements <- function(selection) {
|
|||
inputId = "act_eval",
|
||||
label = i18n$t("Evaluate"),
|
||||
width = "100%",
|
||||
icon = phosphoricons::ph("calculator"),
|
||||
icon = phosphoricons::ph("calculator",weight = "bold"),
|
||||
# icon = shiny::icon("calculator"),
|
||||
disabled = TRUE
|
||||
),
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ update_factor_ui <- function(id) {
|
|||
actionButton(
|
||||
disabled = TRUE,
|
||||
inputId = ns("drop_levels"),
|
||||
label = tagList(phosphoricons::ph("trash"), i18n$t("Drop empty")),
|
||||
label = tagList(phosphoricons::ph("trash",weight = "bold"), i18n$t("Drop empty")),
|
||||
class = "btn-outline-primary mb-3",
|
||||
width = "100%"
|
||||
)
|
||||
|
|
@ -55,7 +55,7 @@ update_factor_ui <- function(id) {
|
|||
actionButton(
|
||||
inputId = ns("sort_levels"),
|
||||
label = tagList(
|
||||
phosphoricons::ph("sort-ascending"),
|
||||
phosphoricons::ph("sort-ascending",weight = "bold"),
|
||||
i18n$t("Sort by levels")
|
||||
),
|
||||
class = "btn-outline-primary mb-3",
|
||||
|
|
@ -68,7 +68,7 @@ update_factor_ui <- function(id) {
|
|||
actionButton(
|
||||
inputId = ns("sort_occurrences"),
|
||||
label = tagList(
|
||||
phosphoricons::ph("sort-ascending"),
|
||||
phosphoricons::ph("sort-ascending",weight = "bold"),
|
||||
i18n$t("Sort by count")
|
||||
),
|
||||
class = "btn-outline-primary mb-3",
|
||||
|
|
@ -92,7 +92,7 @@ update_factor_ui <- function(id) {
|
|||
actionButton(
|
||||
inputId = ns("create"),
|
||||
label = tagList(
|
||||
phosphoricons::ph("arrow-clockwise"),
|
||||
phosphoricons::ph("arrow-clockwise",weight = "bold"),
|
||||
i18n$t("Update factor variable")
|
||||
),
|
||||
class = "btn-outline-primary"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ update_variables_ui <- function(id, title = "") {
|
|||
placement = "bottom-end",
|
||||
shiny::actionButton(
|
||||
inputId = ns("settings"),
|
||||
label = phosphoricons::ph("gear"),
|
||||
label = phosphoricons::ph("gear",weight = "bold"),
|
||||
class = "pull-right float-right"
|
||||
),
|
||||
shinyWidgets::textInputIcon(
|
||||
|
|
@ -75,7 +75,7 @@ update_variables_ui <- function(id, title = "") {
|
|||
shiny::actionButton(
|
||||
inputId = ns("validate"),
|
||||
label = htmltools::tagList(
|
||||
phosphoricons::ph("arrow-circle-right", title = i18n$t("Apply changes")),
|
||||
phosphoricons::ph("arrow-circle-right", title = i18n$t("Apply changes"),weight = "bold"),
|
||||
i18n$t("Apply changes")
|
||||
),
|
||||
width = "100%"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue