refactor: обновление renv, рефактор кода

This commit is contained in:
2026-03-26 22:32:45 +03:00
parent 9dfe4fdda6
commit dbe9ab42bd
4 changed files with 88 additions and 99 deletions

53
app.R
View File

@@ -1,7 +1,6 @@
suppressPackageStartupMessages({ suppressPackageStartupMessages({
library(DBI) library(DBI)
library(RSQLite) library(RSQLite)
library(tibble)
library(tidyr) library(tidyr)
library(dplyr) library(dplyr)
library(purrr) library(purrr)
@@ -65,24 +64,6 @@ inputs_tables_list <- SCHEME_MAIN %>%
tibble::deframe() tibble::deframe()
# SETUP DB ==========================
# #' @description Function to open connection to db, disigned to easy dubugging.
# make_db_connection <- function(where = "") {
# if (DEBUG) message("=== DB CONNECT ", where)
# DBI::dbConnect(RSQLite::SQLite(), dbfile)
# }
# #' @description Function to close connection to db, disigned to easy dubugging and
# #' hide warnings.
# close_db_connection <- function(con, where = "") {
# tryCatch(
# expr = DBI::dbDisconnect(con),
# error = function(e) print(e),
# warning = function(w) if (DEBUG) message("=!= ALREADY DISCONNECTED ", where),
# finally = if (DEBUG) message("=/= DB DISCONNECT ", where)
# )
# }
# establish connection # establish connection
con <- db$make_db_connection() con <- db$make_db_connection()
@@ -124,12 +105,12 @@ if (identical(colnames(DBI::dbReadTable(con, "main")), names(inputs_simple_list)
# add empty data for each new input form # add empty data for each new input form
for (i in form_base_difference) { for (i in form_base_difference) {
df_to_rewrite <- df_to_rewrite %>% df_to_rewrite <- df_to_rewrite |>
dplyr::mutate(!!dplyr::sym(i) := utils$get_empty_data(inputs_simple_list[i])) dplyr::mutate(!!dplyr::sym(i) := utils$get_empty_data(inputs_simple_list[i]))
} }
# reorder due to scheme # reorder due to scheme
df_to_rewrite <- df_to_rewrite %>% df_to_rewrite <- df_to_rewrite |>
dplyr::select(dplyr::all_of(names(inputs_simple_list))) dplyr::select(dplyr::all_of(names(inputs_simple_list)))
DBI::dbWriteTable(con, "main", df_to_rewrite, overwrite = TRUE) DBI::dbWriteTable(con, "main", df_to_rewrite, overwrite = TRUE)
@@ -154,17 +135,17 @@ inline_tables <- purrr::map(
.f = \(x_inline_table_name) { .f = \(x_inline_table_name) {
# получить имя файла со схемой # получить имя файла со схемой
file_name <- SCHEME_MAIN %>% file_name <- SCHEME_MAIN |>
dplyr::filter(form_id == x_inline_table_name) %>% dplyr::filter(form_id == x_inline_table_name) |>
dplyr::pull(choices) dplyr::pull(choices)
# load scheme # load scheme
schemaaa <- readxl::read_xlsx(fs::path(folder_with_schemas, file_name)) %>% schemaaa <- readxl::read_xlsx(fs::path(folder_with_schemas, file_name)) |>
tidyr::fill(dplyr::everything(), .direction = "down") tidyr::fill(dplyr::everything(), .direction = "down")
# список форм в схеме # список форм в схеме
inline_forms <- schemaaa %>% inline_forms <- schemaaa |>
dplyr::distinct(form_id) %>% dplyr::distinct(form_id) |>
dplyr::pull() dplyr::pull()
# макет таблицы (пустой) # макет таблицы (пустой)
@@ -283,11 +264,11 @@ server <- function(input, output) {
.f = \(x_input_id) { .f = \(x_input_id) {
form_type <- inputs_simple_list[[x_input_id]] form_type <- inputs_simple_list[[x_input_id]]
choices <- dplyr::filter(SCHEME_MAIN, form_id == {{x_input_id}}) %>% choices <- dplyr::filter(SCHEME_MAIN, form_id == {{x_input_id}}) |>
dplyr::pull(choices) dplyr::pull(choices)
val_required <- dplyr::filter(SCHEME_MAIN, form_id == {{x_input_id}}) %>% val_required <- dplyr::filter(SCHEME_MAIN, form_id == {{x_input_id}}) |>
dplyr::distinct(required) %>% dplyr::distinct(required) |>
dplyr::pull(required) dplyr::pull(required)
# for `number` type: if in `choices` column has values then parsing them to range validation # for `number` type: if in `choices` column has values then parsing them to range validation
@@ -379,7 +360,7 @@ server <- function(input, output) {
schema <- inline_tables[[x]]$schema schema <- inline_tables[[x]]$schema
# убрать дубликаты # убрать дубликаты
schema_comp <- schema %>% schema_comp <- schema |>
dplyr::distinct(form_id, form_label, form_type) dplyr::distinct(form_id, form_label, form_type)
# заголовки # заголовки
@@ -394,7 +375,7 @@ server <- function(input, output) {
colHeaders = headers, colHeaders = headers,
rowHeaders = NULL, rowHeaders = NULL,
height = 400, height = 400,
) %>% ) |>
rhandsontable::hot_cols( rhandsontable::hot_cols(
colWidths = 120, colWidths = 120,
manualColumnResize = TRUE, manualColumnResize = TRUE,
@@ -404,29 +385,29 @@ server <- function(input, output) {
# циклом итерируемся по индексу; # циклом итерируемся по индексу;
for (i in seq(1, length(schema_comp$form_id))) { for (i in seq(1, length(schema_comp$form_id))) {
# получаем информацию о типе столбца # получаем информацию о типе столбца
type <- dplyr::filter(schema_comp, form_id == schema_comp$form_id[i]) %>% type <- dplyr::filter(schema_comp, form_id == schema_comp$form_id[i]) |>
dplyr::pull(form_type) dplyr::pull(form_type)
# информация о воможных вариантнах выбора # информация о воможных вариантнах выбора
choices <- dplyr::filter(schema, form_id == schema_comp$form_id[i]) %>% choices <- dplyr::filter(schema, form_id == schema_comp$form_id[i]) |>
dplyr::pull(choices) dplyr::pull(choices)
## проверки ## проверки
# текстовое поле # текстовое поле
if (type == "text") { if (type == "text") {
rh_tabel <- rh_tabel %>% rh_tabel <- rh_tabel |>
hot_col(col = headers[i], type = "autocomplete") hot_col(col = headers[i], type = "autocomplete")
} }
# выбор из списка # выбор из списка
if (type == "select_one") { if (type == "select_one") {
rh_tabel <- rh_tabel %>% rh_tabel <- rh_tabel |>
hot_col(col = headers[i], type = "dropdown", source = choices) hot_col(col = headers[i], type = "dropdown", source = choices)
} }
# дата # дата
if (type == "date") { if (type == "date") {
rh_tabel <- rh_tabel %>% rh_tabel <- rh_tabel |>
hot_col(col = headers[i], type = "date", dateFormat = "DD.MM.YYYY", language = "ru-RU") hot_col(col = headers[i], type = "date", dateFormat = "DD.MM.YYYY", language = "ru-RU")
} }
} }

View File

@@ -5,9 +5,7 @@
'Module path: "', basename(box::file()), '"' 'Module path: "', basename(box::file()), '"'
) )
} }
# ================
# DB RELATED ===========================
#' @export #' @export
#' @description Function to open connection to db, disigned to easy dubugging. #' @description Function to open connection to db, disigned to easy dubugging.
#' @param where text mark to distingiush calss #' @param where text mark to distingiush calss

View File

@@ -88,7 +88,6 @@ render_cards_with_forms <- function(sub_group, main_scheme) {
# UI RELATED ============================ # UI RELATED ============================
#' @export #' @export
#' @param TEST s
render_forms <- function( render_forms <- function(
form_id, form_id,
form_label, form_label,
@@ -254,10 +253,10 @@ render_forms <- function(
} }
# SERVER LOGIC ========================== # SERVER LOGIC ==========================
#' @export #' @export
#' @description
#' Функция возращает пустое значение для каждого типа формы
get_empty_data <- function(type) { get_empty_data <- function(type) {
if (type %in% c("text", "select_one", "select_multiple")) return(as.character(NA)) if (type %in% c("text", "select_one", "select_multiple")) return(as.character(NA))
if (type %in% c("radio", "checkbox")) return(as.character(NA)) if (type %in% c("radio", "checkbox")) return(as.character(NA))

127
renv.lock
View File

@@ -81,16 +81,16 @@
}, },
"R.oo": { "R.oo": {
"Package": "R.oo", "Package": "R.oo",
"Version": "1.26.0", "Version": "1.27.0",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"R.methodsS3", "R.methodsS3",
"methods", "methods",
"utils" "utils"
], ],
"Hash": "4fed809e53ddb5407b3da3d0f572e591" "Hash": "6ac79ff194202248cf946fe3a5d6d498"
}, },
"R.utils": { "R.utils": {
"Package": "R.utils", "Package": "R.utils",
@@ -109,13 +109,13 @@
}, },
"R6": { "R6": {
"Package": "R6", "Package": "R6",
"Version": "2.5.1", "Version": "2.6.1",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R" "R"
], ],
"Hash": "470851b6d5d0ac559e9d01bb352b4021" "Hash": "d4335fe7207f1c01ab8c41762f5840d4"
}, },
"RColorBrewer": { "RColorBrewer": {
"Package": "RColorBrewer", "Package": "RColorBrewer",
@@ -231,6 +231,17 @@
], ],
"Hash": "40415719b5a479b87949f3aa0aee737c" "Hash": "40415719b5a479b87949f3aa0aee737c"
}, },
"box": {
"Package": "box",
"Version": "1.2.0",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"tools"
],
"Hash": "d94049c1d9446b0abb413fde9e82a505"
},
"bslib": { "bslib": {
"Package": "bslib", "Package": "bslib",
"Version": "0.8.0", "Version": "0.8.0",
@@ -278,14 +289,14 @@
}, },
"cli": { "cli": {
"Package": "cli", "Package": "cli",
"Version": "3.6.1", "Version": "3.6.4",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"utils" "utils"
], ],
"Hash": "89e6d8219950eac806ae0c489052048a" "Hash": "491c34d3d9dd0d2fe13d9f278bb90795"
}, },
"colorspace": { "colorspace": {
"Package": "colorspace", "Package": "colorspace",
@@ -303,10 +314,10 @@
}, },
"commonmark": { "commonmark": {
"Package": "commonmark", "Package": "commonmark",
"Version": "1.9.0", "Version": "1.9.2",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Hash": "d691c61bff84bd63c383874d2d0c3307" "Hash": "14eb0596f987c71535d07c3aff814742"
}, },
"config": { "config": {
"Package": "config", "Package": "config",
@@ -320,13 +331,13 @@
}, },
"cpp11": { "cpp11": {
"Package": "cpp11", "Package": "cpp11",
"Version": "0.4.7", "Version": "0.5.1",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R" "R"
], ],
"Hash": "5a295d7d963cc5035284dcdbaf334f4e" "Hash": "9df43854f1c84685d095ed6270b52387"
}, },
"crayon": { "crayon": {
"Package": "crayon", "Package": "crayon",
@@ -355,14 +366,14 @@
}, },
"digest": { "digest": {
"Package": "digest", "Package": "digest",
"Version": "0.6.33", "Version": "0.6.37",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"utils" "utils"
], ],
"Hash": "b18a9cf3c003977b0cc49d5e76ebe48d" "Hash": "33698c4b3127fc9f506654607fb73676"
}, },
"dplyr": { "dplyr": {
"Package": "dplyr", "Package": "dplyr",
@@ -400,14 +411,13 @@
}, },
"evaluate": { "evaluate": {
"Package": "evaluate", "Package": "evaluate",
"Version": "0.21", "Version": "1.0.3",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R"
"methods"
], ],
"Hash": "d59f3b464e8da1aef82dc04b588b8dfb" "Hash": "e9651417729bbe7472e32b5027370e79"
}, },
"fansi": { "fansi": {
"Package": "fansi", "Package": "fansi",
@@ -449,14 +459,14 @@
}, },
"fs": { "fs": {
"Package": "fs", "Package": "fs",
"Version": "1.6.3", "Version": "1.6.5",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"methods" "methods"
], ],
"Hash": "47b5f30c720c23999b913a1a635cf0bb" "Hash": "7f48af39fa27711ea5fbd183b399920d"
}, },
"generics": { "generics": {
"Package": "generics", "Package": "generics",
@@ -496,14 +506,14 @@
}, },
"glue": { "glue": {
"Package": "glue", "Package": "glue",
"Version": "1.6.2", "Version": "1.8.0",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"methods" "methods"
], ],
"Hash": "4f2596dfb05dac67b9dc558e5c6fba2e" "Hash": "5899f1eaa825580172bb56c08266f37c"
}, },
"gtable": { "gtable": {
"Package": "gtable", "Package": "gtable",
@@ -522,14 +532,14 @@
}, },
"highr": { "highr": {
"Package": "highr", "Package": "highr",
"Version": "0.10", "Version": "0.11",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"xfun" "xfun"
], ],
"Hash": "06230136b2d2b9ba5805e1963fa6e890" "Hash": "d65ba49117ca223614f71b60d85b8ab7"
}, },
"hms": { "hms": {
"Package": "hms", "Package": "hms",
@@ -636,17 +646,17 @@
}, },
"jsonlite": { "jsonlite": {
"Package": "jsonlite", "Package": "jsonlite",
"Version": "1.8.7", "Version": "1.9.0",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"methods" "methods"
], ],
"Hash": "266a20443ca13c65688b2116d5220f76" "Hash": "a61860f091bd20d8dd6c3fd8ac7f6e90"
}, },
"knitr": { "knitr": {
"Package": "knitr", "Package": "knitr",
"Version": "1.44", "Version": "1.49",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
@@ -658,7 +668,7 @@
"xfun", "xfun",
"yaml" "yaml"
], ],
"Hash": "60885b9f746c9dfaef110d070b5f7dc0" "Hash": "9fcb189926d93c636dea94fbe4f44480"
}, },
"labeling": { "labeling": {
"Package": "labeling", "Package": "labeling",
@@ -709,16 +719,16 @@
}, },
"lifecycle": { "lifecycle": {
"Package": "lifecycle", "Package": "lifecycle",
"Version": "1.0.3", "Version": "1.0.4",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"cli", "cli",
"glue", "glue",
"rlang" "rlang"
], ],
"Hash": "001cecbeac1cff9301bdc3775ee46a86" "Hash": "b8552d117e1b808b09a832f589b79035"
}, },
"lubridate": { "lubridate": {
"Package": "lubridate", "Package": "lubridate",
@@ -905,7 +915,7 @@
}, },
"purrr": { "purrr": {
"Package": "purrr", "Package": "purrr",
"Version": "1.0.2", "Version": "1.0.4",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
@@ -916,7 +926,7 @@
"rlang", "rlang",
"vctrs" "vctrs"
], ],
"Hash": "1cba04a4e9414bdefc9dcaa99649a8dc" "Hash": "cc8b5d43f90551fa6df0a6be5d640a4f"
}, },
"rappdirs": { "rappdirs": {
"Package": "rappdirs", "Package": "rappdirs",
@@ -976,14 +986,14 @@
}, },
"rlang": { "rlang": {
"Package": "rlang", "Package": "rlang",
"Version": "1.1.1", "Version": "1.1.5",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"utils" "utils"
], ],
"Hash": "a85c767b55f0bf9b7ad16c6d7baee5bb" "Hash": "724dcc1490cd7071ee75ca2994a5446e"
}, },
"rmarkdown": { "rmarkdown": {
"Package": "rmarkdown", "Package": "rmarkdown",
@@ -1142,22 +1152,22 @@
}, },
"stringi": { "stringi": {
"Package": "stringi", "Package": "stringi",
"Version": "1.7.12", "Version": "1.8.4",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"stats", "stats",
"tools", "tools",
"utils" "utils"
], ],
"Hash": "ca8bd84263c77310739d2cf64d84d7c9" "Hash": "39e1144fd75428983dc3f63aa53dfa91"
}, },
"stringr": { "stringr": {
"Package": "stringr", "Package": "stringr",
"Version": "1.5.0", "Version": "1.5.1",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"cli", "cli",
@@ -1168,7 +1178,7 @@
"stringi", "stringi",
"vctrs" "vctrs"
], ],
"Hash": "671a4d384ae9d32fc47a14e98bfa3dc8" "Hash": "960e2ae9e09656611e0b8214ad543207"
}, },
"sys": { "sys": {
"Package": "sys", "Package": "sys",
@@ -1268,7 +1278,7 @@
}, },
"vctrs": { "vctrs": {
"Package": "vctrs", "Package": "vctrs",
"Version": "0.6.4", "Version": "0.6.5",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
@@ -1278,7 +1288,7 @@
"lifecycle", "lifecycle",
"rlang" "rlang"
], ],
"Hash": "266c1ca411266ba8f365fcc726444b87" "Hash": "c03fa420630029418f7e6da3667aac4a"
}, },
"viridisLite": { "viridisLite": {
"Package": "viridisLite", "Package": "viridisLite",
@@ -1292,27 +1302,28 @@
}, },
"withr": { "withr": {
"Package": "withr", "Package": "withr",
"Version": "2.5.2", "Version": "3.0.2",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"grDevices", "grDevices",
"graphics", "graphics"
"stats"
], ],
"Hash": "4b25e70111b7d644322e9513f403a272" "Hash": "cc2d62c76458d425210d1eb1478b30b4"
}, },
"xfun": { "xfun": {
"Package": "xfun", "Package": "xfun",
"Version": "0.40", "Version": "0.51",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R",
"grDevices",
"stats", "stats",
"tools" "tools"
], ],
"Hash": "be07d23211245fc7d4209f54c4e4ffc8" "Hash": "e1a3c06389a46d065c18bd4bbc27c64c"
}, },
"xtable": { "xtable": {
"Package": "xtable", "Package": "xtable",
@@ -1328,10 +1339,10 @@
}, },
"yaml": { "yaml": {
"Package": "yaml", "Package": "yaml",
"Version": "2.3.7", "Version": "2.3.10",
"Source": "Repository", "Source": "Repository",
"Repository": "RSPM", "Repository": "CRAN",
"Hash": "0d0056cc5383fbc240ccd0cb584bf436" "Hash": "51dab85c6c98e50a18d7551e9d49f76c"
}, },
"zip": { "zip": {
"Package": "zip", "Package": "zip",