fix: correct data loading

This commit is contained in:
2026-04-13 19:30:27 +03:00
parent 4c3d339361
commit 2f62a94afa
8 changed files with 97 additions and 97 deletions

45
app.R
View File

@@ -11,8 +11,6 @@ suppressPackageStartupMessages({
# КАК ЗАПРЯТЯАТЬ ID
source("helpers/functions.R")
# SOURCE FILES ============================
box::purge_cache()
box::use(
@@ -178,7 +176,7 @@ server <- function(input, output, session) {
} else {
# list of rendered panels
validator_main(data_validation$init_val(mhcs()$get_schema("main")))
validator_main(data_validation$init_val(mhcs()$get_scheme("main")))
validator_main()$enable()
mhcs()$get_main_form_ui
}
@@ -206,8 +204,8 @@ server <- function(input, output, session) {
if (missing(ns)) ns <- NULL
# transform df to list
loaded_df_for_id <- as.list(df)
loaded_df_for_id <- df[input_ids]
# loaded_df_for_id <- as.list(df)
# loaded_df_for_id <- df[input_ids]
# rewrite input forms
purrr::walk2(
@@ -220,7 +218,7 @@ server <- function(input, output, session) {
form_id = x_id,
form_type = x_type,
value = df[[x_id]],
scheme = mhcs()$get_schema(table_name),
scheme = mhcs()$get_scheme(table_name),
ns = ns
)
}
@@ -341,7 +339,7 @@ server <- function(input, output, session) {
key_id <- mhcs()$get_key_id(values$nested_form_id)
# загрузка схемы для данной вложенной формы
this_nested_form_scheme <- mhcs()$get_schema(values$nested_form_id)
this_nested_form_scheme <- mhcs()$get_scheme(values$nested_form_id)
# мини-схема для ключа
this_nested_form_key_scheme <- subset(this_nested_form_scheme, form_id == key_id)
@@ -431,16 +429,17 @@ server <- function(input, output, session) {
con = con
)
col_types <- mhcs()$get_schema_with_values_forms(values$nested_form_id) |>
col_types <- mhcs()$get_scheme_with_values_forms(values$nested_form_id) |>
dplyr::distinct(form_id, form_type, form_label)
date_cols <- which(col_types$form_type == "date")
str_cols <- which(col_types$form_type != "date")
values$data <- values$data |>
select(-mhcs()$get_main_key_id) |>
mutate(
dplyr::across(tidyselect::all_of({{date_cols}}), as.Date)
dplyr::across(tidyselect::all_of({{date_cols}}), as.Date),
dplyr::across(tidyselect::all_of({{str_cols}}), as.character),
) |>
arrange({{key_id}})
@@ -460,7 +459,8 @@ server <- function(input, output, session) {
keys = TRUE
)
) |>
DT::formatDate(date_cols, "toLocaleDateString", params = list('ru-RU'))
DT::formatDate(date_cols, "toLocaleDateString", params = list('ru-RU')) |>
DT::formatString(str_cols)
)
showModal(modalDialog(
@@ -598,7 +598,7 @@ server <- function(input, output, session) {
removeModal()
# та самая форма для ключа
scheme_for_key_input <- mhcs()$get_schema(values$nested_form_id) |>
scheme_for_key_input <- mhcs()$get_scheme(values$nested_form_id) |>
dplyr::filter(form_id == mhcs()$get_key_id(values$nested_form_id))
ui1 <- rlang::exec(
@@ -678,7 +678,7 @@ server <- function(input, output, session) {
observeEvent(input$add_new_main_key_button, {
# данные для главного ключа
scheme_for_key_input <- mhcs()$get_schema("main") |>
scheme_for_key_input <- mhcs()$get_scheme("main") |>
dplyr::filter(form_id == mhcs()$get_main_key_id)
# создать форму для выбора ключа
@@ -864,7 +864,7 @@ server <- function(input, output, session) {
tibble::as_tibble()
# handle with data
scheme <- mhcs()$get_schema(x)
scheme <- mhcs()$get_scheme(x)
date_columns <- subset(scheme, form_type == "date", form_id, drop = TRUE)
number_columns <- subset(scheme, form_type == "number", form_id, drop = TRUE)
@@ -916,10 +916,11 @@ server <- function(input, output, session) {
"---",
"\n"
)
box::use(modules/data_manipulations[is_this_empty_value])
# iterate by scheme parts
purrr::walk(
.x = unique(mhcs()$get_schema("main")$part),
.x = unique(mhcs()$get_scheme("main")$part),
.f = \(x_iter1) {
# write level 1 header
HEADER_1 <- paste("#", x_iter1, "\n")
@@ -927,14 +928,14 @@ server <- function(input, output, session) {
# iterate by level2 headers (subgroups)
purrr::walk(
.x = dplyr::pull(unique(subset(mhcs()$get_schema("main"), part == x_iter1, "subgroup"))),
.x = dplyr::pull(unique(subset(mhcs()$get_scheme("main"), part == x_iter1, "subgroup"))),
.f = \(x_iter2) {
# get header 2 name
HEADER_2 <- paste("##", x_iter2, "\n")
# for some reason set litle scheme...
litle_scheme <- subset(
x = mhcs()$get_schema("main"),
x = mhcs()$get_scheme("main"),
subset = part == x_iter1 & subgroup == x_iter2,
select = c("form_id", "form_label", "form_type")
) |>
@@ -955,7 +956,7 @@ server <- function(input, output, session) {
if (length(docx_value) > 1) docx_value <- paste(docx_value, collapse = ", ")
# if non empty data - add string
if (!check_for_empty_data(docx_value)) paste0("**", docx_label, "**: ", docx_value, "\n") else NA
if (!is_this_empty_value(docx_value)) paste0("**", docx_label, "**: ", docx_value, "\n") else NA
} else if (docx_type == "description") {
# treat description label as citation text
paste0(">", docx_label, "\n")
@@ -1039,7 +1040,7 @@ server <- function(input, output, session) {
for (table_name in mhcs()$all_tables_names) {
df <- openxlsx2::read_xlsx(wb, table_name)
scheme <- mhcs()$get_schema_with_values_forms(table_name)
scheme <- mhcs()$get_scheme_with_values_forms(table_name)
# столбцы в таблицы и схема
df_to_schema_compare <- setdiff(colnames(df), unique(scheme$form_id))
@@ -1064,7 +1065,7 @@ server <- function(input, output, session) {
for (table_name in mhcs()$all_tables_names) {
df <- openxlsx2::read_xlsx(wb, table_name)
scheme <- mhcs()$get_schema_with_values_forms(table_name)
scheme <- mhcs()$get_scheme_with_values_forms(table_name)
date_columns <- subset(scheme, form_type == "date", form_id, drop = TRUE)
number_columns <- subset(scheme, form_type == "number", form_id, drop = TRUE)
@@ -1129,7 +1130,7 @@ server <- function(input, output, session) {
type = "message"
)
cli::cli_alert_success(message)
}
}
log_action_to_db("importing data from xlsx", con = con)
removeModal()
})
@@ -1239,4 +1240,4 @@ server <- function(input, output, session) {
app <- shinyApp(ui = ui, server = server)
runApp(app, launch.browser = TRUE)
runApp(app, launch.browser = TRUE)