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({
library(DBI)
library(RSQLite)
library(tibble)
library(tidyr)
library(dplyr)
library(purrr)
@@ -65,24 +64,6 @@ inputs_tables_list <- SCHEME_MAIN %>%
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
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
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]))
}
# 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)))
DBI::dbWriteTable(con, "main", df_to_rewrite, overwrite = TRUE)
@@ -154,17 +135,17 @@ inline_tables <- purrr::map(
.f = \(x_inline_table_name) {
# получить имя файла со схемой
file_name <- SCHEME_MAIN %>%
dplyr::filter(form_id == x_inline_table_name) %>%
file_name <- SCHEME_MAIN |>
dplyr::filter(form_id == x_inline_table_name) |>
dplyr::pull(choices)
# 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")
# список форм в схеме
inline_forms <- schemaaa %>%
dplyr::distinct(form_id) %>%
inline_forms <- schemaaa |>
dplyr::distinct(form_id) |>
dplyr::pull()
# макет таблицы (пустой)
@@ -283,11 +264,11 @@ server <- function(input, output) {
.f = \(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)
val_required <- dplyr::filter(SCHEME_MAIN, form_id == {{x_input_id}}) %>%
dplyr::distinct(required) %>%
val_required <- dplyr::filter(SCHEME_MAIN, form_id == {{x_input_id}}) |>
dplyr::distinct(required) |>
dplyr::pull(required)
# 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_comp <- schema %>%
schema_comp <- schema |>
dplyr::distinct(form_id, form_label, form_type)
# заголовки
@@ -394,7 +375,7 @@ server <- function(input, output) {
colHeaders = headers,
rowHeaders = NULL,
height = 400,
) %>%
) |>
rhandsontable::hot_cols(
colWidths = 120,
manualColumnResize = TRUE,
@@ -404,29 +385,29 @@ server <- function(input, output) {
# циклом итерируемся по индексу;
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)
# информация о воможных вариантнах выбора
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)
## проверки
# текстовое поле
if (type == "text") {
rh_tabel <- rh_tabel %>%
rh_tabel <- rh_tabel |>
hot_col(col = headers[i], type = "autocomplete")
}
# выбор из списка
if (type == "select_one") {
rh_tabel <- rh_tabel %>%
rh_tabel <- rh_tabel |>
hot_col(col = headers[i], type = "dropdown", source = choices)
}
# дата
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")
}
}

View File

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

View File

@@ -88,7 +88,6 @@ render_cards_with_forms <- function(sub_group, main_scheme) {
# UI RELATED ============================
#' @export
#' @param TEST s
render_forms <- function(
form_id,
form_label,
@@ -254,10 +253,10 @@ render_forms <- function(
}
# SERVER LOGIC ==========================
#' @export
#' @description
#' Функция возращает пустое значение для каждого типа формы
get_empty_data <- function(type) {
if (type %in% c("text", "select_one", "select_multiple")) 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": {
"Package": "R.oo",
"Version": "1.26.0",
"Version": "1.27.0",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"R.methodsS3",
"methods",
"utils"
],
"Hash": "4fed809e53ddb5407b3da3d0f572e591"
"Hash": "6ac79ff194202248cf946fe3a5d6d498"
},
"R.utils": {
"Package": "R.utils",
@@ -109,13 +109,13 @@
},
"R6": {
"Package": "R6",
"Version": "2.5.1",
"Version": "2.6.1",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "470851b6d5d0ac559e9d01bb352b4021"
"Hash": "d4335fe7207f1c01ab8c41762f5840d4"
},
"RColorBrewer": {
"Package": "RColorBrewer",
@@ -231,6 +231,17 @@
],
"Hash": "40415719b5a479b87949f3aa0aee737c"
},
"box": {
"Package": "box",
"Version": "1.2.0",
"Source": "Repository",
"Repository": "RSPM",
"Requirements": [
"R",
"tools"
],
"Hash": "d94049c1d9446b0abb413fde9e82a505"
},
"bslib": {
"Package": "bslib",
"Version": "0.8.0",
@@ -278,14 +289,14 @@
},
"cli": {
"Package": "cli",
"Version": "3.6.1",
"Version": "3.6.4",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"utils"
],
"Hash": "89e6d8219950eac806ae0c489052048a"
"Hash": "491c34d3d9dd0d2fe13d9f278bb90795"
},
"colorspace": {
"Package": "colorspace",
@@ -303,10 +314,10 @@
},
"commonmark": {
"Package": "commonmark",
"Version": "1.9.0",
"Version": "1.9.2",
"Source": "Repository",
"Repository": "CRAN",
"Hash": "d691c61bff84bd63c383874d2d0c3307"
"Hash": "14eb0596f987c71535d07c3aff814742"
},
"config": {
"Package": "config",
@@ -320,13 +331,13 @@
},
"cpp11": {
"Package": "cpp11",
"Version": "0.4.7",
"Version": "0.5.1",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R"
],
"Hash": "5a295d7d963cc5035284dcdbaf334f4e"
"Hash": "9df43854f1c84685d095ed6270b52387"
},
"crayon": {
"Package": "crayon",
@@ -355,14 +366,14 @@
},
"digest": {
"Package": "digest",
"Version": "0.6.33",
"Version": "0.6.37",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"utils"
],
"Hash": "b18a9cf3c003977b0cc49d5e76ebe48d"
"Hash": "33698c4b3127fc9f506654607fb73676"
},
"dplyr": {
"Package": "dplyr",
@@ -400,14 +411,13 @@
},
"evaluate": {
"Package": "evaluate",
"Version": "0.21",
"Version": "1.0.3",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"methods"
"R"
],
"Hash": "d59f3b464e8da1aef82dc04b588b8dfb"
"Hash": "e9651417729bbe7472e32b5027370e79"
},
"fansi": {
"Package": "fansi",
@@ -449,14 +459,14 @@
},
"fs": {
"Package": "fs",
"Version": "1.6.3",
"Version": "1.6.5",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"methods"
],
"Hash": "47b5f30c720c23999b913a1a635cf0bb"
"Hash": "7f48af39fa27711ea5fbd183b399920d"
},
"generics": {
"Package": "generics",
@@ -496,14 +506,14 @@
},
"glue": {
"Package": "glue",
"Version": "1.6.2",
"Version": "1.8.0",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"methods"
],
"Hash": "4f2596dfb05dac67b9dc558e5c6fba2e"
"Hash": "5899f1eaa825580172bb56c08266f37c"
},
"gtable": {
"Package": "gtable",
@@ -522,14 +532,14 @@
},
"highr": {
"Package": "highr",
"Version": "0.10",
"Version": "0.11",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"xfun"
],
"Hash": "06230136b2d2b9ba5805e1963fa6e890"
"Hash": "d65ba49117ca223614f71b60d85b8ab7"
},
"hms": {
"Package": "hms",
@@ -636,17 +646,17 @@
},
"jsonlite": {
"Package": "jsonlite",
"Version": "1.8.7",
"Version": "1.9.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"methods"
],
"Hash": "266a20443ca13c65688b2116d5220f76"
"Hash": "a61860f091bd20d8dd6c3fd8ac7f6e90"
},
"knitr": {
"Package": "knitr",
"Version": "1.44",
"Version": "1.49",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
@@ -658,7 +668,7 @@
"xfun",
"yaml"
],
"Hash": "60885b9f746c9dfaef110d070b5f7dc0"
"Hash": "9fcb189926d93c636dea94fbe4f44480"
},
"labeling": {
"Package": "labeling",
@@ -709,16 +719,16 @@
},
"lifecycle": {
"Package": "lifecycle",
"Version": "1.0.3",
"Version": "1.0.4",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"cli",
"glue",
"rlang"
],
"Hash": "001cecbeac1cff9301bdc3775ee46a86"
"Hash": "b8552d117e1b808b09a832f589b79035"
},
"lubridate": {
"Package": "lubridate",
@@ -905,7 +915,7 @@
},
"purrr": {
"Package": "purrr",
"Version": "1.0.2",
"Version": "1.0.4",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
@@ -916,7 +926,7 @@
"rlang",
"vctrs"
],
"Hash": "1cba04a4e9414bdefc9dcaa99649a8dc"
"Hash": "cc8b5d43f90551fa6df0a6be5d640a4f"
},
"rappdirs": {
"Package": "rappdirs",
@@ -976,14 +986,14 @@
},
"rlang": {
"Package": "rlang",
"Version": "1.1.1",
"Version": "1.1.5",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"utils"
],
"Hash": "a85c767b55f0bf9b7ad16c6d7baee5bb"
"Hash": "724dcc1490cd7071ee75ca2994a5446e"
},
"rmarkdown": {
"Package": "rmarkdown",
@@ -1142,22 +1152,22 @@
},
"stringi": {
"Package": "stringi",
"Version": "1.7.12",
"Version": "1.8.4",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"stats",
"tools",
"utils"
],
"Hash": "ca8bd84263c77310739d2cf64d84d7c9"
"Hash": "39e1144fd75428983dc3f63aa53dfa91"
},
"stringr": {
"Package": "stringr",
"Version": "1.5.0",
"Version": "1.5.1",
"Source": "Repository",
"Repository": "RSPM",
"Repository": "CRAN",
"Requirements": [
"R",
"cli",
@@ -1168,7 +1178,7 @@
"stringi",
"vctrs"
],
"Hash": "671a4d384ae9d32fc47a14e98bfa3dc8"
"Hash": "960e2ae9e09656611e0b8214ad543207"
},
"sys": {
"Package": "sys",
@@ -1268,7 +1278,7 @@
},
"vctrs": {
"Package": "vctrs",
"Version": "0.6.4",
"Version": "0.6.5",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
@@ -1278,7 +1288,7 @@
"lifecycle",
"rlang"
],
"Hash": "266c1ca411266ba8f365fcc726444b87"
"Hash": "c03fa420630029418f7e6da3667aac4a"
},
"viridisLite": {
"Package": "viridisLite",
@@ -1292,27 +1302,28 @@
},
"withr": {
"Package": "withr",
"Version": "2.5.2",
"Version": "3.0.2",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"grDevices",
"graphics",
"stats"
"graphics"
],
"Hash": "4b25e70111b7d644322e9513f403a272"
"Hash": "cc2d62c76458d425210d1eb1478b30b4"
},
"xfun": {
"Package": "xfun",
"Version": "0.40",
"Version": "0.51",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"grDevices",
"stats",
"tools"
],
"Hash": "be07d23211245fc7d4209f54c4e4ffc8"
"Hash": "e1a3c06389a46d065c18bd4bbc27c64c"
},
"xtable": {
"Package": "xtable",
@@ -1328,10 +1339,10 @@
},
"yaml": {
"Package": "yaml",
"Version": "2.3.7",
"Version": "2.3.10",
"Source": "Repository",
"Repository": "RSPM",
"Hash": "0d0056cc5383fbc240ccd0cb584bf436"
"Repository": "CRAN",
"Hash": "51dab85c6c98e50a18d7551e9d49f76c"
},
"zip": {
"Package": "zip",